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 –