students=int(input('输入学生人数:') 计数器=1
while(counter<;=学生):
name = input('Please enter student ' + str(counter) + ' name:')
score = int(input('Please enter student ' + str(counter) + ' score:'))
lowest = 100
secondlowest = 100
if (score < lowest):
secondlowest = lowest
lowest = score
elif score > lowest and score < secondlowest:
secondlowest = score
counter = counter + 1
print("2nd lowest student is " + name + " with score " + str(secondlowest))
你只需要两个变量来记录最低的两个分数
如果最新分数低于最低分数,则更新该分数并将第二个最低分数设置为第一个分数
否则,如果最新的分数低于当前第二低的分数,只需用新值更新它。
相关问题 更多 >
编程相关推荐