我一直在努力使用此功能来捕获用户输入中的错误。
def user_choice():
choice = 4
while choice > 3
choice = int(input("what list is your card in"))
return choice
任何想法将不胜感激。 感谢
答案 0 :(得分:0)
这可以通过使用您想要的有效参数实现一个数组来完成,然后使用in
关键字检查它是否存在。
def user_choice():
choice = int(input('what list is your card in?: '))
valid = [1,2,3]
if choice in valid:
return choice
else:
print('oops! must be between 1-3 please try again')
user_choice()