In: Computer Science
Write a program in python to calculate the amount each person must pay toward the bill and toward the tip, for a group of friends who are eating out together. Since you are all friends, it is okay to split the costs evenly.
Your program should take as input:
Your program should output:
For example, with the following inputs:
Restaurant bill (without tax or tip): $35 Sales tax rate: 0.08 Level of service: 7 Number of friends: 3
the output should be:
Bill per person with tax: $12.6 Tip per person: $2.4499999999999997 Total per person: $15.049999999999999 Total bill including tax and tip: $45.15
Note that because floating point values often incur rounding errors, the output might not be completely accurate. This will not affect the grading. However, please make your input and output look like the example above, so that the automated system can evaluate your results.
Things to think about when you’re writing these programs:
PYTHON CODE:
# Input part billWithoutTax = float(input('Restaurant bill (without tax or tip): $')) taxRate = float(input('Sales tax rate: ')) serviceLevel = int(input('Level of service: ')) numOfFriends = int(input('Number of friends: ')) # Calculation part billWithTax = billWithoutTax + billWithoutTax*taxRate billPerPersonWithTax = billWithTax/numOfFriends totalTip = billWithoutTax*serviceLevel*3/100 tipPerPerson = totalTip/numOfFriends totalPerPerson = billPerPersonWithTax + tipPerPerson totalBillWithTaxTip = totalPerPerson*numOfFriends # Output part print('Bill per person with tax: $', billPerPersonWithTax) print('Tip per person: $', tipPerPerson) print('Total per person: $', totalPerPerson) print('Total bill including tax and tip: $', totalBillWithTaxTip)
SAMPLE OUTPUT: