python
2017-03-06 23 views -2 likes 
-2

这是我的编码迄今的程序,允许用户创建一个清单

numofthings=int(input("How many things do you need to pack? ")) 
numoftasks=int(input("How many tasks do you need to complete to prepare? ")) 

checklist1=[] 
end=' ' 
while end.lower()!='end': 
    item=input("Please enter the things you need to pack and type 'End' when you're done: ") 
    checklist1.append(item) 
    end=item 

checklist2=[] 
end=' ' 
while end.lower()!='end': 
    task=input("What tasks do you have to complete and type 'End' when you're done ") 
    checklist2.append(task) 
    end=task 
print(checklist1) 
print(checklist2) 

如何得到他们列表保存的项目到一个数组/列表? 另外我该如何做到这一点,以便他们只能列出他们说他们必须打包的物品数量?

我才开始编码2个星期前很抱歉,如果很明显,我已经忽略了它

+0

你的问题是什么?有什么不符合你的期望? – FamousJameous

回答

0

如何得到他们列表保存的项目到一个数组/列表?

你已经这样做就好了:这就是你

checklist.append(item) 

得到如果您在循环坚持一个简单的报告声明,你会看到这种情况发生,当您去:

checklist.append(item) 
print(checklist) 

在您打开程序之前注释该行。

我怀疑你需要两个独立的检查清单,但是:每一个包装和任务。

我该如何做到这一点,以便他们只能列出他们说他们必须打包的 的数量?

决定你打算如何决定你有足够的时间。您当前的代码查找触发器值“结束”。如果你知道你有多少次迭代你进入循环前,然后用循环:

for i in range(num_of_things): 

这是否让你感动?

+0

谢谢,它现在有效。 – Zigzag

相关问题