players = input("How many players?")
if players == "1":
p1 +=1
elif players == "2":
p2 +=1
else:
print("Invalid Input")
players = input("How many players?")
如果输入无效输入,我怎样才能重复其他?
答案 0 :(得分:6)
输入时使用无限循环和break
:
while True:
players = input("How many players?")
if players == "1":
p1 += 1
break
elif players == "2":
p2 += 1
break
else:
print("Sorry, please pick 1 or 2. Let's try again")