Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sales tax calculator with a while loop

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.

like image 637
nickg Avatar asked Mar 28 '26 19:03

nickg


1 Answers

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}")
like image 110
Joseph Hogan Avatar answered Mar 30 '26 12:03

Joseph Hogan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!