【发布时间】:2015-11-13 08:16:11
【问题描述】:
我不确定我在这里做错了什么。我正在尝试将用户输入限制为 1-6(骰子游戏)。逻辑正常,但是当引发 ValueError() 时,它不会再次提示用户。
try:
while True:
choice = input('Enter number to hold - type D to roll: ')
print(choice)
if choice == 'D':
return choice_list
elif len(choice) > 1 or choice not in '12345':
raise ValueError()
else:
choice_list[int(choice) - 1] = 'X'
printer(roll_list, choice_list)
except ValueError:
print ("Invalid input")
【问题讨论】:
标签: python-3.x try-except