Python Day 2: Operators




Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal's total cost.

Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result!



  1. #!/bin/python
  2. import math
  3. import os
  4. import random
  5. import re
  6. import sys
  7. # Complete the solve function below.
  8. def solve(meal_cost, tip_percent, tax_percent):
  9. # Write your calculation code here
  10. tip = (tip_percent/100)* meal_cost # calculate tip
  11. tax = (tax_percent/100)* meal_cost# caclulate tax
  12. # cast the result of the rounding operation to an int and save it as total_cost
  13. total_cost = round(meal_cost+tip+tax)
  14. print(total_cost)
  15. if __name__ == '__main__':
  16. meal_cost = float(input())
  17. tip_percent = int(input())
  18. tax_percent = int(input())
  19. solve(meal_cost, tip_percent, tax_percent)
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube