我正在尝试创建一个收银机程序。我的目标是所有的产品都被添加,并找到最终的价格。如果不知道以前的价值观,我怎么能达到这个目标?下面是我的代码。提前感谢您的帮助,不胜感激
responses = {}
polling_active = True
print("Welcome to the cash register. Insert your product name and price to be able to calculate your final total")
total = 0
while polling_active:
product = input("\nProduct Name: ")
total += float(input("Price: "))
responses[product] = total
repeat = input("Is this your final checkout? (Yes/No)")
if repeat == 'no':
polling_active = True
elif repeat == 'No':
polling_active = True
elif repeat == 'Yes':
polling_active = False
elif repeat == 'yes':
polling_active = False
else:
print("That operation is invalid")
print("\n---Final Checkout---")
for product, price in responses.items():
print(product + " is $" + str(total))
print("\n---Total Price---")
print("Store Price is: ")
print("$" + str(total))
print("\n---Tax Price---")
print("Your price with tax is: ")
total = total * 1.13
print("$" + "{0:.2f}".format(float(total)))
print("\nThank you for shopping with us! Have a great day!")
我理解与我目前的代码,总数将不允许我添加任何产品,但这只是目前的一个位置持有人
以下是您需要的代码:
输出:
整数:
浮动:
相关问题 更多 >
编程相关推荐