作业帮 > 综合 > 作业

Write a program which allows the user to input a list of fiv

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/11 15:10:16
Write a program which allows the user to input a list of five numbers.
Write a program which allows the user to input a list of five numbers,then tells them the smallest,largest and median of the numbers they have entered.Hint:use the .sort() method of the list.
def largest(data):
return data[len(data)-1]
def smallest(data):
return data[0]
def median(data):
return sum(data)*1.0/len(data)
def calc(data):
data.sort()
print 'Largest:  ' + str(largest(data))
print 'Smallest: ' + str(smallest(data))
print 'Median:   ' + str(median(data))
if __name__ == '__main__':
data = [10,9,6,10,5,-1,7,18,9,7,2,3,0,10,23]
calc(data)