Advertisement
The_KGB

[Python-Lab4] Challenge Solution

Apr 23rd, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. #This program uses functions and variables
  2.  
  3. #the main function
  4. def main():
  5.     print 'Welcome to the meal calculator program'
  6.     print   #prints a blank line
  7.     mealprice = input_meal()
  8.     percent = calPercent(mealprice)
  9.     tip = calc_tip(mealprice, percent)
  10.     tax = calc_tax(mealprice)
  11.     total = calc_total(mealprice, tip, tax)
  12.     print_info(mealprice, tip, tax, total)
  13.    
  14. #this function will calculate tip at 20%
  15. def calc_tip(mealprice, percent):
  16.     tip = mealprice * percent
  17.     return tip
  18.  
  19. #CalcPercent
  20. def calPercent(mealprice):
  21.     if mealprice <= 5.99:
  22.         percent = .1
  23.     elif mealprice <= 12 and mealprice >= 6:
  24.         percent = .13
  25.     elif mealprice <= 17 and mealprice >= 12.01:
  26.         percent = .16
  27.     elif mealprice <= 25 and mealprice >= 17.01:
  28.         percent = .19
  29.     elif mealprice >= 25.01:
  30.         percent = .22
  31.     return percent
  32.    
  33. #this function will calculate tax at 6%
  34. def calc_tax(mealprice):
  35.     tax = mealprice * .06
  36.     return tax
  37.  
  38. #this function will calculate tip, tax, and the total #cost
  39. def calc_total(mealprice, tip, tax):
  40.     total = mealprice + tip + tax
  41.     return total
  42.  
  43. #this function will print tip, tax, the mealprice, and #the total
  44. def print_info(mealprice, tip, tax, total):
  45.     print 'The meal price is $', mealprice
  46.     print 'The tip is $', tip
  47.     print 'The tax is $', tax
  48.     print 'The total is $', total
  49.  
  50. #this function is for the meal
  51. def input_meal():
  52.     mealprice = input('Enter the meal price $')
  53.     mealprice = float(mealprice)
  54.     return mealprice
  55.    
  56.    
  57. #calls main
  58. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement