0
我剛剛開始使用Python,我正在爲一個任務編寫程序。描述是爲了將電子設備連接到購物車。當購物者開始購物時,設備將詢問購物者他們的預算,這是購物者想要花費的最大量。然後,它會要求購物者輸入他們放在購物車中的每件物品的成本。每次將東西添加到購物車時,設備都會將該物品的成本添加到購物車中所有物品成本的運行總額或總和中。一旦所有物品的成本超過預算,它會提醒購物者他們花了太多錢。如何在Python中添加多個用戶輸入
我已經繪製出了代碼和種類,找出了我需要做的一切。但我無法正確地添加用戶的多個輸入。理想情況下,它應該添加用戶的第一個輸入與他們的第二和第三等,並停止當用戶進入所有完成。
這是我的代碼到目前爲止。任何指針將不勝感激!
budget = 0
itemCost = 0
cartTotal = 0
print ("Hello! Welcome to the best grocery store ever!")
budget = int (input ("What is your budget for today? "))
itemCost = int (input ("Please tell me the cost of the most recent item your cart. Print ALL DONE to quit "))
while itemCost != "All DONE" and cartTotal <= budget:
itemCost = int (input ("Please tell me the cost of the most recent item your cart. Print ALL DONE to quit ")) #works
cartTotal = itemCost + itemCost
print ("OK, the items in your cart cost a total of ", cartTotal)
print ("Your budget is ", budget, " you have spent ", cartTotal, " you have ", budget - cartTotal, " left over.")
else:
print ("You are a horrible budgeter!")
你不允許數量超過1 –