102k views
2 votes
Calculator Create a program that calculates three options for an appropriate tip to leave after a meal at a restaurant.

Specifications:

a. The program should calculate and display the cost of tipping at 15%, 20%, or 25%.
b. Assume the user will enter valid data.
c. The program should round results to a maximum of two decimal places.

User Frigon
by
5.9k points

1 Answer

3 votes

Answer:

I am writing a Python program:

print("Tip Calculator \\")

bill = float(input("Cost of meal: "))

tip15pc = bill * 0.15

tip20pc = bill * 0.20

tip25pc = bill * 0.25

print("\\15%")

print("Tip amount: %.2f"% (tip15pc))

print("Total amount: %.2f \\" % (bill + tip15pc))

print("20%")

print("Tip amount: %.2f"% (tip20pc))

print("Total amount: %.2f \\" % (bill + tip20pc))

print("25%")

print("Tip amount: %.2f"% (tip25pc))

print("Total amount: %.2f" % (bill + tip25pc))

Step-by-step explanation:

The program first prints the message: Tip Calculator

bill = float(input("Cost of meal: ")) This statement prompts the user to enter the amount of the bill of meal. The input value is taken as decimal/floating point number from user.

tip15pc = bill * 0.15 This statement calculates the cost of tipping at 15%

tip20pc = bill * 0.20 This statement calculates the cost of tipping at 20%

tip25pc = bill * 0.25 This statement calculates the cost of tipping at 25%

print("\\15%") This statement prints the message 15%

print("Tip amount: %.2f"% (tip15pc)) this statement displays the amount of tip at 15% and the value is displayed up to 2 decimal places as specified by %.2f

print("Total amount: %.2f \\" % (bill + tip15pc)) This statement prints the total amount by adding the cost of mean with the 15% tip amount.

The program further computes the the amount of tip at 20% and 25%. The resultant values are displayed up to 2 decimal places as specified by %.2f Then the program prints the total amount by adding the cost of mean with the 20% and 25% tip amounts just as computed for the 15% tip.

The screenshot of the program as well as its output is attached.

Calculator Create a program that calculates three options for an appropriate tip to-example-1
User Alberto Rossi
by
6.5k points