Ask Question
8 December, 07:45

Input a total dinner amount (ex. $55.40) and the number of guest. The function should calculate the total cost (including 15% tip) and as equally as possible distribute the cost of the entire meal between the number of provided guests. (e. g., splitTip (15.16, 3) = => guest1-$5.06, guest2-$5.05, guest3-$5.05). Whatever logic is used for uneven amounts should be deterministic and testable (all values rounded to cents - 2 decimal places).

+1
Answers (1)
  1. 8 December, 11:07
    0
    def splitTip (totalCost, numGuest) : finalCost = totalCost * 0.15 + totalCost avgCost = finalCost / numGuest for i in range (numGuest) : print ("Guest " + str (i+1) + ": $" + str (round (avgCost, 2))) splitTip (15.16,3)

    Explanation:

    The solution is written in Python 3.

    To calculate the average cost shared by the guests, we create a function that takes two input, totalCost and numGuest (Line 1). Next apply the calculation formula to calculate the final cost after adding the 15% tips (Line 2). Next calculate the average cost shared by each guest by dividing the final cost by number of guest (Line 3). At last, use a for loop to print out the cost borne by each guest (Line 4-5).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Input a total dinner amount (ex. $55.40) and the number of guest. The function should calculate the total cost (including 15% tip) and as ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers