这是我想要的,但对于整数。我不允许使用BREAK或CONTINUE退出循环感谢
$#basically i need this, but with an int(input('please enter a numb
ask = input('Would you like to play Steal or Deal [y|n]? ')
while ask not in ('y', 'n'):
print ("Please enter either 'y' or 'n'")
print('')
ask = input('Would you like to play Steal or Deal [y|n]? ')
答案 0 :(得分:0)
您可以尝试将字符串转换为int并捕获异常:
def is_number(s):
try:
int(s)
return True
except ValueError:
return False
ask = input('please enter a number: ')
while not is_number(ask):
print ("no, a number!")
print('')
ask = input('please enter a number: ')