214k views
1 vote
Write a split check function that returns the amount that each diner must pay to cover the cost of the meal The function has 4 parameters:

1. bill: The amount of the bill,
2. people. The number of diners to split the bill between
3. tax_percentage: The extra tax percentage to add to the bill.
4. tip_percentage: The extra tip percentage to add to the bill.
The tax or tip percentages are optional and may not be given when caling split_check. Use default parameter values of 0.15 (15%) for tip percentage, and 0.09 (9%) for tax_percentage
Sample output with inputs: 252
Cost per diner: 15.5
Sample output with inputs: 100 2 0.075 0.20
Cost per diner: 63.75
1 # FIXME: write the split.check function: HINT: Calculate the amount of tip and tax,
2 # add to the bill total, then divide by the number of diners
3.
4. Your solution goes here
5.
6. bill - float(input)
7. people intinout)
8.
9. Cost per diner at the default tax and tip percentages
10. print('Cost per diner: split_check(bill, people))
11.
12. bill - float(input)
13. people int(input)
14. newtax_percentage - float(input)
15. nen_tip percentage float(input)
16.
17. Oust per dinero different tox and tip percentage
18. print('Cost per diner: split checkbull people, new tax percentage, new tip percentage)

1 Answer

2 votes

Answer:

def split_check(bill, people, tax_percentage = 0.09, tip_percentage = 0.15):

tip = bill * tip_percentage

tax = bill * tax_percentage

total = bill + tip + tax

return total / people

bill = float(input())

people = int(input())

print("Cost per diner: " + str(split_check(bill, people)))

bill = float(input())

people = int(input())

new_tax_percentage = float(input())

new_tip_percentage = float(input())

print("Cost per diner: " + str(split_check(bill, people, new_tax_percentage, new_tip_percentage)))

Step-by-step explanation:

Create a function called split_check that takes four parameters, bill, people, tax_percentage and tip_percentage (last two parameters are optional)

Inside the function, calculate the tip and tax using the percentages. Calculate the total by adding bill, tip and tax. Then, return the result of total divided by the number of people, corresponds to the cost per person.

For the first call of the function, get the bill and people from the user and use the default parameters for the tip_percentage and tax_percentage. Print the result.

For the second call of the function, get the bill, people, new_tip_percentage and new_tax_percentage from the user. Print the result.

User Josh Young
by
4.1k points