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

User Smoothumut
by
8.4k points

1 Answer

7 votes

Complete Question:

Python Programming: Create a program that calculates three options for an appropriate tip to leave after a meal at a restaurant and repeats if the user enters "y" or "Y" to continue.

Print the name of the application "Tip Calculator"

- Get input from the user for "Cost of meal: "

- Calculate and display the "Tip Amount" and "Total Amount" at a tip_percent of 15%, 20%, and 25%.

- Use a FOR loop to iterate through the tip_percent

- The formula for calculating the tip amount is: tip = cost of meal * (tip percent / 100)

- The program should accept decimal entries like 52.31. Assume the user will enter valid data.

- The program should round the results to a maximum of two decimal places . At the "Continue? (y/n)" prompt, the program should continue only if the user enters “y” or “Y” to continue.

- Print "Bye!" or a salutation at the end of the program

Answer:

Answered in Python

print("Tip Calculator")

tryagain = "y"

while tryagain == "y" or tryagain == "Y":

amount = float(input("Cost of Meal: "))

for tip_percent in range(15,26,5):

print(str(tip_percent)+"%")

print("Tip Amount: "+str(round(tip_percent * amount/100,2)))

print("Total Amount: "+str(round(amount + (tip_percent * amount/100),2)))

tryagain = input("Continue?y/n: ")

print("Bye!")

Step-by-step explanation:

This prints the name of the calculator

print("Tip Calculator")

This initializes tryagain to yes

tryagain = "y"

While tryagain is yes, the following loop is repeated

while tryagain == "y" or tryagain == "Y":

This prompts user for amount of meal

amount = float(input("Cost of Meal: "))

This gets the tip_percent which is 15%, 20% and 25% respectively

for tip_percent in range(15,26,5):

This prints the tip_percent

print(str(tip_percent)+"%")

This calculates and prints the tip amount rounded to 2 decimal places

print("Tip Amount: "+str(round(tip_percent * amount/100,2)))

This calculates and prints the total amount rounded to 2 decimal places

print("Total Amount: "+str(round(amount + (tip_percent * amount/100),2)))

This prompts user to continue or not

tryagain = input("Continue?y/n: ")

The program ends here

print("Bye!")

User Methodsignature
by
7.8k points