Answer:
- 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)
Step-by-step 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).