Knowee
Questions
Features
Study Tools

Complete the bonAppetit function in the editor below. It should print Bon Appetit if the bill is fairly split. Otherwise, it should print the integer amount of money that Brian owes Anna.bonAppetit has the following parameter(s):bill: an array of integers representing the cost of each item orderedk: an integer representing the zero-based index of the item Anna doesn't eatb: the amount of money that Anna contributed to the bill

Question

Complete the bonAppetit function in the editor below. It should print Bon Appetit if the bill is fairly split. Otherwise, it should print the integer amount of money that Brian owes Anna.bonAppetit has the following parameter(s):bill: an array of integers representing the cost of each item orderedk: an integer representing the zero-based index of the item Anna doesn't eatb: the amount of money that Anna contributed to the bill

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python solution for the bonAppetit function:

def bonAppetit(bill, k, b):
    # Calculate the total bill
    total_bill = sum(bill)
    
    # Subtract the cost of the item Anna didn't eat
    fair_bill = (total_bill - bill[k]) // 2
    
    # Check if the bill is fairly split
    if b == fair_bill:
        print('Bon Appetit')
    else:
        # Print the amount Brian owes to Anna
        print(b - fair_bill)

This function works as follows:

  1. It first calculates the total cost of all items in the bill.
  2. Then it subtracts the cost of the item that Anna didn't eat and divides the result by 2 to get the amount that each person should pay if the bill is split fairly.
  3. It then checks if the amount Anna contributed (b) is equal to the fair amount. If it is, it prints 'Bon Appetit'.
  4. If the amount Anna contributed is not equal to the fair amount, it means Brian owes her some money. The function then calculates this amount by subtracting the fair amount from the amount Anna contributed, and prints this value.

This problem has been solved

Similar Questions

ample Input 04 13 10 2 912Sample Output 05Explanation 0Anna didn't eat item , but she shared the rest of the items with Brian. The total cost of the shared items is and, split in half, the cost per person is . Brian charged her for her portion of the bill. We print the amount Anna was overcharged, , on a new line.Sample Input 1

Two friends Anna and Brian, are deciding how to split the bill at a dinner. Each will only pay for the items they consume. Brian gets the check and calculates Anna's portion. You must determine if his calculation is correct.

Write a query to display the sum of payable_amount and fine_amount of all the bills from bill table. Give an alias name to the sum of payable amount and fine amount as 'sum_payable_and_fine_amount'.Note:1. Display only the sum of payable_amount and fine_amount from bill table.2. Specify the alias name without any mistake.3. Compare your executed result with the sample output given below.Sample output:

Write a query to display the number of bills having fine_amount. Give an alias name as 'count_of_bills_with_fine'.Note:1. Display only the number of bills having the fine_amount from bill table. (If fine_amount is greater than 0 then it indicates that bill got fine_amount.)2. Specify the alias name without any mistake.3. Specify condition on fine_amount column of bill table.3. Compare your executed result with the sample output given below.Sample output:

Write a query to display the minimum fine_amount present in the bill table. Give an alias name to the minimum fine_amount as 'min_fine_amount'.Note:1. Display only the minimum fine_amount from bill table.2. Specify the alias name without any mistake.3. Compare your executed result with the sample output given below.Sample output:

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.