【发布时间】:2021-11-06 18:07:41
【问题描述】:
在第二行中,我试图让它在输入字符串但找不到使用异常或类似内容的方法时不会崩溃。在while循环中它正常工作,因为异常处理这种情况。
number = 0 #this to be removed
number = (float(input('pick a number'))) #I want to make this not crash if a string is entered.
while number not in [100, 200, 3232]:
try:
print('wrong number ')
number = (float(input('pick a number;'))) #Here it does not crash if a string is entered which is fine
except ValueError:
print("retry")
【问题讨论】: