Python 3.7 List

profiledavidsenzu
Assignment7-1.docx

Assignment 7 – Lists

List Operations: Write the following functions in Python which take a list as a input parameter and does the following:

· def range( number_list ):

# returns range of the list. Range is largest number in the list – the smallest number in the list.

· def sum( number_list ):

#returns the sum of the numbers in the list.

· def average( number_list ):

#returns mean or average. Use the sum (..) function(previous fn) to calculate the average.

· def median( number_list ):

#returns median of the list. Median is the middle number of the list after the list is sorted. If numbers are even, median is the average of the two middle numbers.

· def clip( number_list, clipNum ):

# returns the clipped array based on the clipNum. Clipping an array is replacing all the numbers greater than the number provided to that number. So for example if the list is [3,17,5,9,1,11] and the clipNum is 8, returned array is [3,8,5,8,1,8]. So all numbers greater than the clipNumber (here 8) is replaced by the clipNum(which is 8 in this example). clipNum that takes a maximum value as an argument and changes any value in the list that is higher than the specified maximum value to be the same as the maximum value. This function could also be called “haircut”, in that it takes values that are too high, and cuts them down to the maximum allowable height. (Think of a scissor going through your hair and trimming the ones that are too long.)

Within the main ask the user to enter a set of 10 numbers. The program should store the numbers in a list, call each of the functions provided above and display the return values within main() with meaningful messages as shown below:

Given List:

Range of the List is

Sum of the List is

Average of the List is

Median of the List is

Clipped List clipped on the number __ is:

(You can hard code the clipNum or ask it to be provided as a user input)

All functions should be in one file named ListFunctionsFirstname.py with your first name substituted and please submit as a zip file.