while True:
restart=False
userguess=int(input("guess"))
if userguess not in range(0,100):
restart=True
break
if userguess>computerguess:
print("guessed higher")
elif userguess<computerguess:
print("guessed lower")
else:
print("congrats, userguess equals computerguess")
break
/ *如果猜测数字超出0到100范围,我想循环中断。有用。但是在那之后,我想再次询问用户输入,如果下一个值在范围内,我希望循环重新启动。请帮助* /
答案 0 :(得分:0)
使用继续而不是中断
while True:
restart=False
userguess=int(input("guess"))
if userguess not in range(0,100):
restart=True
break
if userguess>computerguess:
print("guessed higher")
elif userguess<computerguess:
print("guessed lower")
else:
print("congrats, userguess equals computerguess")
continue