-3
markList=[]
while True:
    mark=float(input("Enter your marks here(Click -1 to exit)"))
    if mark == -1:  break
    markList.append(mark)

markList.sort()
mid = len(markList)//2
if len(markList)%2==0:
    median=(markList[mid]+ markList[mid-1])/2
    print("Median:", median)

else:
    print("Median:" , markList[mid])     #please do not touch anything starting from this line and above, I have already found the median with this and all Im looking for it to 

find out the lowest and highest grades, this program is asking for the user to input their grades and it telss you the highest, lowest and grade average

min(mark)
print("The lowest mark is", min(mark))

max(mark)
print("The highest mark is", max(mark))
4

1 回答 1

1

无论如何,我都不是 Python 专家,但我已经学习了一些基础知识。您可以在此处参考有关该list对象的文档:

http://docs.python.org/2/library/functions.html#max

listpython中的对象允许一个min()max()函数。您甚至可以在对列表进行排序之前调用它们,例如:

print min(marklist)print max(marklist)

由于您已经对列表进行了排序以进行中位数计算,因此您还可以分别检索列表中的第一项和最后一项,作为最低和最高标记:

print marklist[0] #prints the first/0-index position in the list

同样是最大值,因为 python 支持列表对象的反向索引:

print marklist[-1] #prints the last position in the list

我用这个简单的代码测试了它:

marklist=[]
marklist=[10,13,99,4,3,5,1,0,22,11,6,5,38]
print min(marklist),max(marklist)
marklist.sort()
print marklist[0],marklist[-1]
于 2013-10-30T02:28:11.110 回答