如何在Python中将用户的输入添加到列表中 [英] How do you add input from user into list in Python

查看:1365
本文介绍了如何在Python中将用户的输入添加到列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

print ('This is your Shopping List')          
firstItem = input('Enter 1st item: ')         
print (firstItem)             
secondItem = input('Enter 2nd item: ')           
print (secondItem)  

我该如何列出用户所说的内容,然后在完成后将其打印出来?

How do I make a list of what the user has said then print it out at the end when they have finished?

我又如何询问他们是否在列表中添加了足够的项目?如果他们拒绝,它将打印出已存储的项目列表.

Also how do I ask if they have added enough items to the list? And if they say no then it will print out the list of items already stored.

谢谢,我是新来的,所以我真的不知道.

Thanks, I'm new to this so I don't really know.

推荐答案

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

这篇关于如何在Python中将用户的输入添加到列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆