In: Computer Science
2. Add a title comment block to the top of the new Python file using the following form # A brief description of the project
3. Ask user - to enter the charge for food
4. Ask user - to enter theTip for server ( remember this is a percentage , the input therefore should be decimal. For example, for a 15% tip, 0.15 should be entered)
5. Ask user - to enter the Tax amount ( this is a percentage too, so for a 6% tax , 0.06 should be entered)
6. Calculate tip and tax
7. Display the following: *Calculated tip *Calculated tax *Display total cost of meal ( food charge + tip+ tax)
8. What is the finished code solution file(s)
Notes: the tip , tax and amount are to be requested from the user, they are NOT hard coded (fixed amounts) Write program Pseudocode ( detail algorithm) and add it as a comment block to the submitted program.
'''
Python version : 2.7
Python program to calculate the total cost of meal
'''
'''
Pseudocode:
1. Input the charge of food, tip percent and tax percent from user
2. Calculate tax = charge*taxPercent
3. Calculate tip = (charge+tax)*tipPercent
4. Calculate total charge = charge+tax+tip
5. Display tip, tax and total charge
'''
# input the charge of food
cost = float(raw_input('Enter the charge for food : '))
# input the tip as percent value
tipPercent = float(raw_input('Enter the tip for the server : '))
# input the tax as percent value
taxPercent = float(raw_input('Enter the tax amount : '))
# calculate the total tax on the food
tax = cost*taxPercent
# calculate total cost as cost + tax
totalCost = cost + tax
# calculate the tip on total amount
tip = totalCost*tipPercent
# add tip to total cost
totalCost += tip
# print the tip, tax and total charge of meal
print('Calculated tip : $%.2f' %(tip))
print('Calculated tax : $%.2f' %(tax))
print('Display total cost of meal : $%.2f' %(totalCost))
#end of program
Code Screenshot:
Output: