Can anyone help me figure out this code in python? This example will demonstrate
ID: 3805767 • Letter: C
Question
Can anyone help me figure out this code in python?
This example will demonstrate how to parse an input string into a list of numbers. You will then demonstrate it's a list of numbers by calculating the count sum (), min (), max () and average of the numbers using Python's len () sum (), min (), and max (), functions. Example Run #1: Enter numbers separated by a space: 10 5 0| Numbers: [10.0, 5.0, 0.0] Count: 3 Min: 0.0 Max: 10.0 Sum: 15.0 Average: 5.0 Example Run #2: (Handles bad input) Enter numbers separated by a space: 5 mike 3 Error: mike is not a number! As usual, write the program, THEN figure out how to handle bad input Start out your program by writing your TODO list of steps you'11 need to solve the problem! #TODO: Write Todo list then beneath write your code # Write code here numbers = []Explanation / Answer
ln = raw_input("Enter numbers separated by space:")
ln = ln.split()
nm = []
for a in ln:
try:
nm.append(float(a))
except:
print("Error: "+a+" is not a number")
exit()
print("Numbers: "+str(nm))
print("Count: "+str(len(nm)))
print("Min: "+str(min(nm)))
print("Max: "+str(max(nm)))
print("Sum: "+str(sum(nm)))
avg = (sum(nm)*1.0)/len(nm)
print("Average: "+str(avg))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.