• Save
  • Download
  • Clear Output
  • Runtime
  • Run All Cells

Loading Runtime

Exercise 1

Make a list that contains exactly five integers - each as separate elements within the list.

Save the list to a variable called 'five_ints`

[1, 2, 3, 4, 5]

List Generator Function

This isn't an exercise, just some code that will help you complete the later exercises.

The code cell below uses some code techniques (that we haven't talked about yet) to generate a random list of numbers. Each time you run the code cell a different list will be generated and saved to the variable random_list

Please run the code cell at least once before completing the rest of the exercises below. Don't stress out if the code in this code cell doesn't make sense to you.

[2, 5, 4, 6, 1, 10, 3, 10, 8, 3, 8, 8, 7, 3]

Exercise 2 - Length of a List

Create a variable called list_length and use the len() function to store the number of items in random_list to the variable list_length.

14

Exercise 3 - Sum of a list

Create a variable called list_sum and use the len() function to store the sum of all integers in random_list to the variable list_sum.

78

Exercise 4 - Mean of a list

Write a function called mean that takes in a list of numbers as an argument and returns the statistical mean of the passed-in list.

5.571428571428571

Exercise 5 - Even or Odd Length?

Write a function called even_odd that takes in a list. The function should calculate the length of the list and if the length is an odd number return the string "odd". If the length is an even number, the function should return the string "even".

even

Exercise 6 - List Range

Write a function called list_range that takes in a list of numbers as an argument and returns the difference between the highest value in the list and the lowest value in the list.

In other words, calculate the highest number in the list (the max) as well as the lowest number in the mist (the min) and then return the result of the maximum value minus the minimum value.

9