Reputation: 123
I am making a sales tax calculator and everything works besides the total payment amount portion. In my program I want to be able to input a number and get the taxed amount on the item I also want to be able to get the total amount payed including tax in the transaction. The code I have written so far does all of that but when I input a second number I want that numbers total payment to be added to the previous total payment. for example if you input 3.99 it gives you a total payment of 4.3441125000000005 then if you input 12.95 it should give you a total payment of 18.443425 because 12.95's total payment is 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)
so I basically just want the totals to add each time you input a cost.
Upvotes: 3
Views: 971
Reputation: 80
You could create a new variable:
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}")
Upvotes: 2