Due 10/21 at 11:59
When you eat at a restaurant, you often need to calculate a tip and split the bill. Instead of doing the math in your head, write a program that does it for you!
Your program must meet the following specifications:
calculate_tip that takes a bill amount and tip percentage and returns the tip amountcalculate_total that takes a bill amount and tip amount and returns the totalsplit_bill that takes a total and number of people and returns the cost per personFor example, if the user enters a $40.00 bill, 20 percent tip, and 2 people, your program might print:
Bill: $40.00
Tip (20%): $8.00
Total: $48.00
Each person pays: $24.00
A function is a reusable block of code. Use the def keyword to define a function, and use return to send a value back to the code that called it:
def add_tax(price, tax_rate):
tax = price * tax_rate
return price + tax
total = add_tax(10, 0.08)
print(total) # 10.8
Here is a starting point. Fill in the TODO comments to meet the specifications above!
def calculate_tip(bill, tip_percent):
# TODO: calculate and return the tip amount
pass
def calculate_total(bill, tip):
# TODO: calculate and return the total
pass
def split_bill(total, people):
# TODO: calculate and return the cost per person
pass
# Ask the user for input
bill = float( input("Enter the bill amount: $") )
tip_percent = float( input("Enter the tip percentage: ") )
people = int( input("How many people are splitting the bill? ") )
# Call your functions
# TODO
# Print the results
# TODO
round(amount, 2))0 people, print an error message instead of dividingWhen you’re happy with your tip calculator, download the .py file and submit it on Thinkwave.