Write a program that will calculate a XXX% tip and a 6% tax on a meal price. The
ID: 3692330 • Letter: W
Question
Write a program that will calculate a XXX% tip and a 6% tax on a meal price. The user will enter the meal price and the program will calculate tip, tax, and the total. The total is the meal price plus the tip plus the tax. Your program will then display the values of tip, tax, and total.
The restaurant now wants to change the program so that the tip percent is based on the meal price. The new amounts are as follows:
Meal Price Range
Tip Percent
.01 to 5.99
10%
6 to 12.00
13%
12.01 to 17.00
16%
17.01 to 25.00
19%
25.01 and more
22%
Meal Price Range
Tip Percent
.01 to 5.99
10%
6 to 12.00
13%
12.01 to 17.00
16%
17.01 to 25.00
19%
25.01 and more
22%
Explanation / Answer
def main():
mealPrice = getPrice()
tip = getTip(mealPrice)
tax = getTax(mealPrice)
total = getTotal(mealPrice, tip, tax)
printAll(tip, tax, total)
def getPrice():
mealPrice = input ("Enter your meal price: $")
mealPrice = float (mealPrice)
return mealPrice
def getTip(mealPrice):
if mealPrice >= .01 and mealPrice <= 5.99:
tip = mealPrice * .01
elif mealPrice >= 6 and mealPrice <= 12:
tip = mealPrice * .13
elif mealPrice >= 12.01 and mealPrice <= 17:
tip = mealPrice * .16
elif mealPrice >= 17.01 and mealPrice <= 25:
tip = mealPrice * .19
else:
tip = mealPrice * .22
tip = float(tip)
return tip
def getTax(mealPrice):
tax = mealPrice * .06
tax = float(tax)
return tax
def getTotal(mealPrice, tip, tax):
total = mealPrice + tip + tax
return total
def printAll(tip, tax, total):
print "Your tip is $", tip
print "Your tax is $", tax
print "Your total bill is $", total
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.