Write code snippets to do the following. You should write these in a Python editor and test them out as you go. When they work, copy and paste your final code snippet here.
Define a function that takes a total bill and the number of people at your table, and prints the amount that each person owes.
e.g. divide_bill(100, 5) would produce
Each person owes $20 for their meal.
e.g. divide_bill(50.25, 4)would produce
Each person owes $12.56 for their meal.
Note that the decimal number above may not be exactly the same as what you get. Yours might say 20.0 or 12.5625, for instance. We’ll learn about how to round to exactly two decimal points later (for Added Fun you could google how to do it now).
Make sure that you test your function by calling it at least twice in your main with different parameters.
Please comment, if you need any corrections.Please give a Thumps up if you like the answer.
Program
def divide_bill(amount,persons):
meal_cost=amount/persons
print("Each person owes $",format(meal_cost, ',.2f'), " for their
meal.")
divide_bill(100, 5)
divide_bill(50.25,4)
Output
Each person owes $ 20.00 for their meal.
Each person owes $ 12.56 for their meal.
Program Screenshot
Get Answers For Free
Most questions answered within 1 hours.