My instructions are: You are going to write a tip-calculating program that does the following:
- Asks the user to enter the subtotal of a restaurant bill
- Asks the user if they wish to enter a tip and if they do, let them choose to enter the tip by a specific amount, or by percentage of the subtotal.
- Display the receipt: Subtotal, Taxed Owed (13%), Tip, Final Total
I feel like I have too many print statements. How can I make it so there is one that works for all of them?
subtotal= float(input("Please enter the subtotal of your bill:"))
print("\nPlease select an option:")
print("1. Enter tip percentage (%)")
print("2. Enter tip amount ($)")
print("3. No tip")
choice= float(input("How would you like to tip?"))
tax= subtotal*0.13
if choice == 1:
tip_percentage= float(input("Please enter the percentage you would like to tip (%):"))
if tip_percentage > 0:
percent_decimal= tip_percentage/100
tip_1= subtotal*percent_decimal
finaltotal_1= subtotal + tax + tip_1
if subtotal > 0:
print("\nSubtotal:", (round(subtotal,2)))
print("Tax Owed:", (round(tax,2)))
print("Tip:", (round(tip_1,2)))
print("Final total:", (round(finaltotal_1,2)))
else:
print("Please try again.")
if choice == 2:
tip_2= float(input("Please enter the tip amount:"))
if tip_2 > 0:
finaltotal_2= subtotal + tax + tip_2
if subtotal>0 and tip_2>0:
print("\nSubtotal:", (round(subtotal,2)))
print("Tax Owed:", (round(tax,2)))
print("Tip:", (round(tip_2,2)))
print("Final total:", (round(finaltotal_2,2)))
else:
print("Please try again.")
if choice == 3:
tip_3= 0
finaltotal_3= subtotal + tax + tip_3
if subtotal>0:
print("\nSubtotal:", (round(subtotal,2)))
print("Tax Owed:", (round(tax,2)))
print("Tip:", (round(tip_3,2)))
print("Final total:", (round(finaltotal_3,2)))
else:
print("Please try again.")