Write a Python program that takes a list of numbers as input from the user and prints the sum, average, minimum, and maximum of the numbers in the list.
Answer:
Answer by student
def my_sum (numbers): total = 0 for num in numbers: total += num return total
def my_min (numbers): minimum = numbers[ 0 ] for num in numbers: if num < minimum: minimum = num return minimum
def my_max (numbers): maximum = numbers[ 0 ] for num in numbers: if num > maximum: maximum = num return maximum
user_input = input( "Enter the numbers separated by commas: " ) numbers = [float(num) for num in user_input.split( "," )] total = my_sum(numbers) average = total / len(numbers) minimum = my_min(numbers) maximum = my_max(numbers) print( "The sum of the numbers is" , total) print( "The average of the numbers is" , average) print( "The minimum of the numbers is" , minimum) print( "The maximum of the numbers is" , maximum) |
Detailed answer by teachoo
The rest of the post is locked. Join Teachoo Black to see the full post.