嘿即時通訊在Python上製作一個簡單的小雜貨清單。我知道這不是最雄辯的......但我現在只是在學習語法。我想進入學習Django。Python嵌套如果
list = []
def makeList():
listing = True
while listing:
addTo = raw_input("Add to list: ")
if addTo == 'q':
listing = False
else:
list.append(addTo)
def checkList():
if check in list:
print "Yay there is " + check + " here"
else:
print "No you have not added that..."
addAnother = raw_input("Would you like to add it? ")
if str.lower(addAnother) == "yes":
list.append(check)
elif str.lower(addAnother) == "no":
print "Okay then here is your list."
print list
else:
print check
makeList()
check = raw_input("What item: ")
checkList()
我知道它很複雜,很難理解O_O ...但你可以看到,如果嵌套,當你運行它語句不登記。
這是做什麼的?我認爲這是問這個問題的最好方法。
請問您可以添加輸出嗎?直到我們知道代碼輸出的內容(以及它應該輸出什麼內容)之前,很難確切地說出問題所在。 –
你的代碼沒有問題。有什麼問題? – aIKid
我只是跑它,它工作正常。你可能想解釋你看到的是什麼樣的行爲,以及你希望幫助人們弄清楚什麼是錯的。也許你期望它在不存在的情況下就像循環一樣。也許你已經混合了製表符和空格,並且你的縮進被打破了,但是你的代碼在這裏沒有明顯的錯誤。 –