Python: how to use list as source of selection for user input?

前端 未结 2 512
梦毁少年i
梦毁少年i 2021-02-04 13:39

Can anyone check this code and let me know what is wrong?

input_list = [\"One\", \"Two\", \"Three\"]
P1 = input(\"Select the input: \", input_list[0], input_list         


        
2条回答
  •  礼貌的吻别
    2021-02-04 14:21

    Take a look at the documentation of the input function: https://docs.python.org/2/library/functions.html#input

    input presents a prompt and evaluates the data input by the user as if it were a Python expression. If you just want to gather data input by the user, use raw_input instead. You'll need to implement custom logic to make sure the user's input matches with something in your list.

提交回复
热议问题