即使我已经输入了 -100 到 100 之间的分数,我仍然卡住了。为什么会这样?请帮我修一下!
players = int(input("Enter number of players: "))
while (players < 2 or players > 10): #Limits number of players to 2-10 only
players = int(input("Error. Players should be 2-10 only. Enter number of players: "))
scores = input("Enter scores separated by space: ")
data = list(map(int, scores.split()))
record = data[slice(players)]
for x in record:
while( x < -100 or x > 100):
scores = input("Error. Scores should be -100 to 100 only. Please enter scores again separated by space: ")
data = list(map(int, scores.split()))
record = data[slice(players)]
record.sort(reverse= True)
values = []
for x in record:
if x not in values:
values.append( x )
if len(values) == 3:
break
print ("The runner-up score is:",values[1])
这是发生了什么:
Enter number of players: 3
Enter scores separated by space: 10000 2 3
Error. Scores should be -100 to 100 only. Please enter scores again separated by space: 233 4 5
Error. Scores should be -100 to 100 only. Please enter scores again separated by space: 1 2 3
Error. Scores should be -100 to 100 only. Please enter scores again separated by space:
可以看到,第三次我已经输入了1 2 3,但是还是报错。
请帮助我:(非常感谢您的帮助!
慕盖茨4494581
白猪掌柜的
相关分类