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.

Respuesta :

Answer:

I am writing a Python program:

print("Tip Calculator \n")

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

tip15pc = bill * 0.15

tip20pc = bill * 0.20

tip25pc = bill * 0.25

print("\n15%")

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

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

print("20%")

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

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

print("25%")

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

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

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("\n15%")  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 \n" % (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.

Ver imagen mahamnasir