Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab 04: Tip, Tax, and Total Python code for the following programming problem. W

ID: 3624246 • Letter: L

Question

Lab 04: Tip, Tax, and Total

Python code for the following programming problem.

Write a program that will calculate a 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 has a fixed tip percent based on the meal price. The tip percent 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%

Use at least six modules (one for input of meal price, one to calculate the tip amount, one to calculate the tax amount, one to calculate the total bill amount, one to display the results, and the main module) in developing the logic.

Explanation / Answer

def main(): meal = get_price() data = calc(meal) total = get_total(data) show(data, total) def get_total(data): return data[0]+data[1]+data[2] def show(data, total): meal = data[0] tip = data[1] tax = data[2] print "Meal price: $", round(meal,2) print "Tip: $", round(tip,2) print "Tax: $", round(tax,2) print "Total: $", round(total,2) def calc(meal): tip, tax = 0,0 tip = get_tip(meal) tax = get_tax(meal+tip) return [meal,tip,tax] def get_price(): meal = input("Enter the meal price: ") return meal def get_tip(cost): if cost > .01: if cost < 5.99: return .1*cost elif cost < 12.00: return .13*cost elif cost < 17.00: return .16*cost elif cost < 25.00: return .19*cost else: return .22*cost else: print "error: meal price must be positive" def get_tax(subtotal): return .06*subtotal main() Note: I'm all for modular code, but this is a little ridiculous.