Ask Question
14 September, 13:53

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).

+5
Answers (1)
  1. 14 September, 14:57
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers