我的代码工作正常,直到我想从我的Tscore数组中输出得分最高的学生的最高得分。我的程序现在只输出第一个得分。请帮忙!
Name=[]
Test1=[]
Test2=[]
Test3=[]
Tscore=[]
sum=0
for i in range(3):
validinput1= False
validinput2= False
validinput3= False
sname=input("Enter your name:")
while not validinput1:
test1=int(input("Enter your score for test 1:"))
if test1<0 or test1>20:
print("Invalid input")
else:
validinput1= True
while not validinput2:
test2=int(input("Enter your score for test 2:"))
if test2<0 or test2>25:
print("Invalid input")
else:
validinput2= True
while not validinput3:
test3=int(input("Enter your score for test 3:"))
if test3<0 or test3>35:
print("Invalid input")
else:
validinput3= True
total=test1+test2+test3
Name.append(sname)
Test1.append(test1)
Test2.append(test2)
Test3.append(test3)
Tscore.append(total)
sum=sum+total
avg=sum/3
for i in range(3):
print(Name[i]," total score: ", Tscore[i])
print(Name[i],"got the highest score: ", max(Tscore[i]))
print("The average of the class is: ", avg)
我想打印所有3名学生的姓名和总分,然后输出所有学生的班级平均分,然后输出学生姓名的最高分。
答案 0 :(得分:0)
您需要max(Tscore)
和不 max(Tscore[i])
来查找列表的最大值。
print(Name[i],"got the highest score: ", max(Tscore))