3
markList=[]
Lmark=0
Hmark=0
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])

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

    Hmark==(max(mark))
    print("The highest mark is", Hmark)

My program is a basic grade calculator using lists. My program asks the user to input their grades into a list in which it then calculates your average and finds your lowest and highest mark. I have found the average but I can't seem to figure out how to find the lowest and highest grade. Can you please show me pr tell me what to do?

4

1 回答 1

2

您的代码有两个问题:

  • ==是比较运算符,不是赋值
  • 标记是你的最后一个成绩,而不是成绩列表

这些最小/最大行应为:

Lmark = min(markList)
Hmark = max(markList)

或者,因为您的列表已经排序:

Lmark = markList[0]
Hmark = markList[-1]
于 2013-11-03T03:46:43.700 回答