gpt4 book ai didi

python - 带有 while 循环的销售税计算器

转载 作者:行者123 更新时间:2023-12-05 04:44:46 27 4
gpt4 key购买 nike

我正在制作销售税计算器,除了总支付金额部分外,其他一切都正常。在我的程序中,我希望能够输入一个数字并获得该项目的税额我还希望能够获得支付的总金额,包括交易中的税金。到目前为止,我编写的代码完成了所有这些工作,但是当我输入第二个数字时,我希望将该数字的总付款额添加到之前的总付款额中。例如,如果您输入 3.99,它给您的总付款是 4.3441125000000005 那么如果您输入 12.95,它应该给您的总付款是 18.443425,因为 12.95 的总付款是 14.0993125 + 4.3441125000000005。

rate = 0.08875 #sales tax
amount = 1
while amount != 0:
amount = float(input("Enter item cost in dollars, 0 to quit: ")) #cost of item
tax = amount*rate #tax amount on item
total = amount+tax #total payment including tax
print("Tax amount on this item ==", tax)
print("Total payment ==", total)

所以我基本上只想在您每次输入成本时添加总计。

最佳答案

您可以创建一个新变量:

rate = 0.08875 #sales tax
amount = 1
full_total = 0
while amount != 0:
amount = float(input("Enter item cost in dollars, 0 to quit: ")) #cost of item
tax = amount*rate #tax amount on item
total = amount+tax #total payment including tax
full_total += total
print("Tax amount on this item ==", tax)
print("Total payment ==", total)
print(f"Your full total today is {full_total}")

关于python - 带有 while 循环的销售税计算器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69276966/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com