In: Computer Science
v
Write a program that calculates and displays different suggested tip amounts, much like you see at the bottom of restaurant bills. Here is a sample execution:
Sample Execution:
Enter the total bill amount: $50
Suggested Tip Amounts: 10%: $5.00(for okay service) 15%: $7.50(for good service) 20%: $10.00(for great service) Total with tip: $57.50
Requirements:
2 pts - When you name your file use your last name – for example: LastNameHW04.py
3 pts - Place a comment at the top of your code with your name and the purpose of the program.
10 pts - The program should start by asking the user for input exactly in the form
below. Their response (input) should be stored in a variable. The amount they enter should be converted to a float in order to allow for decimals to be entered and to do math using it.
Enter the total bill amount: $
15 pts - Use three lines of code to store the 10%, 15% and 20% tip values into three different variables.
10 pts - Variables names must follow Python standard naming conventions.
5 pts – For output, the program should first display the statement below on one line:
Suggested Tip Amounts:
30 pts – Next, use three lines of code to print the calculated tip amounts exactly as shown below. There should not be a space after the $, and to output the % symbol, enter %%. The values in red below will vary based on the user input:
10%: $5.00(for okay service) 15%: $7.50(for good service) 20%: $10.00(for great service)
5 pts - Include additional comments throughout your code explaining what your code does. Remember comments start with #.
20 pts - Extend the program to output an addendum to the receipt that adds a mandatory 15% tip to the total bill amount. You will need an additional variable to store the final cost after adding the tip to the toal bill amount. Output the final total.
Prompt for input
Example of Input: 50
Total with tip: $57.50
""" Name: Your Name This program calculates tip amounts on a bill amount """ # Ask user to enter bill amount, convert it into float before storing in variables bill_amount = float(input('Enter the total bill amount: $')) # Calculate tip amount with 10%, 15%, 20% tip ten_percent_tip = bill_amount * 10 / 100 fifteen_percent_tip = bill_amount * 15 / 100 twenty_percent_tip = bill_amount * 20 / 100 # Print tip amounts print('Suggested Tip Amounts:') print('10%%: $%0.2f(for okay service)' % ten_percent_tip) print('15%%: $%0.2f(for good service)' % fifteen_percent_tip) print('20%%: $%0.2f(for great service)' % twenty_percent_tip) # Calculate mandatory tip - 15% mandatory_tip = bill_amount * 15 / 100 total_bill_with_tip = bill_amount + mandatory_tip # Print total bill print('Total with tip: $%0.2f' % total_bill_with_tip)
SCREENSHOT
OUTPUT