Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 3.x python 3.4中的用户输入列表值_Python 3.x_List_User Input - Fatal编程技术网

Python 3.x python 3.4中的用户输入列表值

Python 3.x python 3.4中的用户输入列表值,python-3.x,list,user-input,Python 3.x,List,User Input,这个代码可以工作,但它不是我需要的 lst = range(1,17) 它使用1到16来进行一些计算,但事实上,当我在代码中键入值时,我想指定这些值: lst = (14, 1, 6, 8) 但我想要的是用户必须通过输入来选择列表中的值 我试过这个,但不起作用 lst = (a1, a2, a3) a1 = int(input("number 1: ")) a2 = int(input("number 2: ")) a3 = int(input("number 3: ")) 您必须切换代码

这个代码可以工作,但它不是我需要的

lst = range(1,17)
它使用1到16来进行一些计算,但事实上,当我在代码中键入值时,我想指定这些值:

lst = (14, 1, 6, 8)
但我想要的是用户必须通过输入来选择列表中的值

我试过这个,但不起作用

lst = (a1, a2, a3)
a1 = int(input("number 1: "))
a2 = int(input("number 2: "))
a3 = int(input("number 3: "))

您必须切换代码行的顺序:

a1 = int(input("number 1: "))
a2 = int(input("number 2: "))
a3 = int(input("number 3: "))
lst = (a1, a2, a3)

Python将以自上而下的顺序逐行执行示例代码,因此,如果您想从输入的值创建列表/元组,那么创建必须是最后一个

我可以猜测您的代码是如何不工作的,但是您需要明确说明发生了什么,以及您期望发生什么。不要只是说有些东西不起作用。