Jul-01-2017, 01:44 AM
I am fresh into a programming fundamentals course, so yes, I have looked at python documentation on how to do what I am asking, I just don't have the coding experience to implement it. Super simple "express checkout" code, however, due to how python does math, I get more than 2 decimal places for the sales tax and total outputs. I am just trying to figure out how to stop the results at 2 decimal places as no one needs to see 15 decimal places on their receipt.
Welcome to the Express Lane!
What is the price of the Frst item: $4.2
What is the price of the second item: $6.35
What is the price of the third item: $4
What is the price of the fourth item: $4
What is the price of the last item: $4
Subtotal: $ 22.55
Sales Tax: $ 1.353
-----------------------------
Total $ 23.903000000000002
Process finished with exit code 0
Had a PyCharm screenshot put can't post it.
print("Welcome to the Express Lane!") price1 = float(input("What is the price of the Frst item: $")) price2 = float(input("What is the price of the second item: $")) price3 = float(input("What is the price of the third item: $")) price4 = float(input("What is the price of the fourth item: $")) price5 = float(input("What is the price of the last item: $")) subtotal = float(price1 + price2 + price3 + price4 + price5) sales_tax = subtotal * 0.06 total = subtotal + sales_tax print("Subtotal: $", subtotal) print("Sales Tax: $", sales_tax) print("-----------------------------") print("Total $", total)OUTPUT:
Welcome to the Express Lane!
What is the price of the Frst item: $4.2
What is the price of the second item: $6.35
What is the price of the third item: $4
What is the price of the fourth item: $4
What is the price of the last item: $4
Subtotal: $ 22.55
Sales Tax: $ 1.353
-----------------------------
Total $ 23.903000000000002
Process finished with exit code 0
Had a PyCharm screenshot put can't post it.