python
2017-03-06 74 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

相關問題