Full Solution to lists HW13:
#-----------------------
def summarizeList(numberString):
#Split numbers at ,
splitlist = numberString.split(",")
# convert numbers to floats
for i in range(len(splitlist)):
splitlist[i] = float(splitlist[i])
# sort the list of numbers small to large
splitlist.sort()
# extract the max and min (since the list is sorted small->large)
small = splitlist[0]
big = splitlist[-1]
#Find the mean (can use builtin sum function, or could use a loop to find the sum)
mean = sum(splitlist) / len(splitlist)
#Find median (tricky!)
l = len(splitlist)
if (l % 2 == 1): #odd len, 1 unique median
median = splitlist[l//2] #e.g.: [0,1,2], len=3, med at i=1 (not 1.5! need to // to get int)
else: #even len, need avg of 2 medians
m2 = splitlist[l//2] #e.g.: [0, 1, 2, 3] #len=4, meds at i=1&2
m1 = splitlist[l//2-1]
median = (m1+m2)/2
# Putting it all together:
# The parentheses let us break up the expression
# over multiple lines
return ("Numbers range from " + str(small)
+ " to " + str(big) + ";"
+ " The median is " + str(median) + ";"
+ " The average is " + str(mean) + ";")