pyt*_*wag 4 python list shopping
print ('This is your Shopping List')
firstItem = input('Enter 1st item: ')
print (firstItem)
secondItem = input('Enter 2nd item: ')
print (secondItem)
Run Code Online (Sandbox Code Playgroud)
如何列出用户所说的内容,然后在完成后将其打印出来?
另外我如何询问他们是否在列表中添加了足够的项目?如果他们拒绝,那么它将打印出已存储的项目列表.
谢谢,我是新手,所以我真的不知道.
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
Run Code Online (Sandbox Code Playgroud)
下面的代码允许用户输入项目,直到他们按Enter键停止:
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]:
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
113807 次 |
| 最近记录: |