Question

In: Computer Science

Write a program in python to calculate the amount each person must pay toward the bill...

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:

  1. The restaurant bill (without tax or tip) as a floating point number
  2. The sales tax rate as a floating point number (for example: an 8% tax rate would be 0.08)
  3. The level of service as an integer between 0 and 10
    0 is terrible (0% tip), 5 is average (15% tip), and 10 is excellent (30% tip)
  4. The number of friends to split the check among

Your program should output:

  1. The amount each friend should pay toward the bill (with tax)
  2. The amount each friend should leave in tip
    tip should be calculated on the pre-tax restaurant bill
  3. The total amount each diner should pay, including restaurant bill, sales tax, and tip
  4. The overall total, which includes the restaurant bill, the sales tax, and the tip

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:

  1. Follow the recipe: collect all your input first; then calculate the required results; then output the results.
  2. Spend some time choosing your variable names carefully. Names should be descriptive.
  3. Take advantage of variables to name values whose purpose may not be obvious.
  4. Take advantage of variables by breaking any complex expressions down into a set of simpler expressions and storing the intermediate results in variables

Solutions

Expert Solution

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:


Related Solutions

Write a program to help a small company calculate the amount of money to pay its...
Write a program to help a small company calculate the amount of money to pay its employees. In this simplistic world, the company has exactly three employees. However, the number of hours per employee may vary. The company will apply the same tax rate to every employee The program must be written in Java. Prompt the user for the inputs and store the values in variables Must include all the inputs and outputs listed here and perform the calculations correctly...
Using C++ Write a program to calculate the amount a customer should pay in a checkout...
Using C++ Write a program to calculate the amount a customer should pay in a checkout counter for the purchases in a bagel shop. The products sold are bagels, cream cheese, and coffee. Use the pseudo code discussed in the class to write the program. Make reasonable assumptions about the prices of bagel, cream cheese, and coffee. Declare prices of bagel, cream cheese, and coffee as constants.
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
This program will calculate the amount for a semester bill at The University of Nantucket. Part...
This program will calculate the amount for a semester bill at The University of Nantucket. Part 1: Create a class Course.java: The class has non-static instance variables: private String department private int courseNumber private int courseCredits private double courseCost The class must have a default constructor which will set values as follows: department = 0 courseNumber = 0 courseCost = 0 The class must a non-default constructor which will set values as follows: department = value passed to constructor courseNumber...
Calculate the amount of money that a person must have in a bank today (the beginning...
Calculate the amount of money that a person must have in a bank today (the beginning of the year) to be able to withdraw $375 at the end of each year for the next 10 years if the bank pays interest compounded yearly at j1 = 5.8% pa. Give your answer in dollars and cents to the nearest cent. Account balance = $ Calculate the simple interest rate pa that must be earned for $60,000 invested on 29 October 2019...
Create a Python program that will calculate the user’s net pay based on the tax bracket...
Create a Python program that will calculate the user’s net pay based on the tax bracket he/she is in. Your program will prompt the user for their first name, last name, their monthly gross pay, and the number of dependents. The number of dependents will determine which tax bracket the user ends up in. The tax bracket is as followed: 0 – 1 Dependents : Tax = 20% 2 – 3 Dependents : Tax = 15% 4+ Dependents :    Tax...
Clint wrote a check to pay for his phone bill. The amount of the bill was...
Clint wrote a check to pay for his phone bill. The amount of the bill was $50. He wrote out the words "Fifty dollars only" but he also wrote "$60" in the area for numbers. As a result, the check: qualifies as a negotiable instrument, and the payee can collect $60. is disqualified as a negotiable instrument. qualifies as a negotiable instrument, and the payee can collect $50. is disqualified as a negotiable instrument, unless Clint's intent is ascertained.
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
KNOWING THE WRITE CHECKS VS. ENTER BILL/PAY BILL AND WHY OR WHEN TO USE EACH ONE
KNOWING THE WRITE CHECKS VS. ENTER BILL/PAY BILL AND WHY OR WHEN TO USE EACH ONE
Overview For this assignment, write a program that will calculate the amount that a customer spends...
Overview For this assignment, write a program that will calculate the amount that a customer spends on tickets at a movie theater. This program will be continued in program 3 so it is important that this program is completed. Basic Program Logic The basic logic for this program is similar to program 1: the user is asked to enter values, a calculation is performed, and the result of the calculation is displayed. For this program, prompt the user for the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT