我正在尝试分析用户输入并且只允许输入整数。我已经成功地只允许在一定范围内使用 100 的面额,但我无法弄清楚如何提示用户在输入随机字符串时重新输入数据。尝试使用“try”命令只会导致程序卡住:
while True:
try:
bet=int(raw_input('Place your bets please:'))
except ValueError:
print 'l2type'
#The following receives a betting amount from the user, and then assesses whether it is a legal bet or not. If not, the user is prompted to enter a legal bet.
while True:
if bet%100==0 and 100<=bet<=20000:
print bet,"Your bet has been accepted, can you make a million?"
break
else:
print bet,"Please enter a legal bet. The table minimum is 100, with a maximum of 20000 in increments of 100."
bet = input('Place your bets please:')