如何在Python中将用户输入添加到列表中
我如何列出用户所说的话,然后在他们说完后打印出来 另外,我如何询问他们是否已将足够的项目添加到列表中?如果他们说不,那么它将打印出已经存储的项目列表 谢谢,我是新手,所以我真的不知道。如何在Python中将用户输入添加到列表中,python,list,shopping,Python,List,Shopping,我如何列出用户所说的话,然后在他们说完后打印出来 另外,我如何询问他们是否已将足够的项目添加到列表中?如果他们说不,那么它将打印出已经存储的项目列表 谢谢,我是新手,所以我真的不知道。shopList=[] print ('This is your Shopping List') firstItem = input('Enter 1st item: ') print (firstItem) secondItem = input('E
shopList=[]
print ('This is your Shopping List')
firstItem = input('Enter 1st item: ')
print (firstItem)
secondItem = input('Enter 2nd item: ')
print (secondItem)
maxLengthList=6
而len(购物清单)
下面的代码允许用户输入项目,直到按enter键停止:
shopList = []
maxLengthList = 6
while len(shopList) < maxLengthList:
item = input("Enter your Item to the List: ")
shopList.append(item)
print shopList
print "That's your Shopping List"
print shopList
list.append(变量)
如果您是新手,请花些时间阅读。
In [1]: items=[]
...: i=0
...: while 1:
...: i+=1
...: item=input('Enter item %d: '%i)
...: if item=='':
...: break
...: items.append(item)
...: print(items)
...:
Enter item 1: apple
Enter item 2: pear
Enter item 3: #press enter here
['apple', 'pear']
In [2]: