Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在函数中捕获用户输入时出错_Python_Input - Fatal编程技术网

Python 在函数中捕获用户输入时出错

Python 在函数中捕获用户输入时出错,python,input,Python,Input,我一直在努力使用这个函数来捕获用户输入的错误 def user_choice(): choice = 4 while choice > 3 choice = int(input("what list is your card in")) return choice 任何想法都将不胜感激。 感谢只需使用所需的有效参数实现一个数组,然后在关键字中使用,检查是否存在 def user

我一直在努力使用这个函数来捕获用户输入的错误

def user_choice():
            choice = 4
            while choice > 3
                    choice = int(input("what list is your card in"))
            return choice
任何想法都将不胜感激。
感谢

只需使用所需的有效参数实现一个数组,然后在关键字中使用
,检查是否存在

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()

你说错误是什么意思?这有用吗?或者你是在谈论丢失的结肠<代码>选项>3:
不,这不是冒号,只是如果没有输入数字1,2,3,我该如何让它再次问这个问题?请参阅我当时提供的第一个链接,简单的sol将是
选项不在范围(1,4):
定义用户选择():选择=4而选择不在范围(1,4):选择=int(输入(“您的卡在什么列表中”))返回选项