aolivens

Python Metric Weight Conversion

Sep 20th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. #=====================================#
  2. #==============MODULES================#
  3. #=====================================#
  4.  
  5.  
  6.  
  7. #=====================================#
  8. #==============VARIABLES==============#
  9. #=====================================#
  10.  
  11. var = 2.2046
  12. menus = ["(1) Lbs to Kgs", "(2) Kgs to Lbs", "(3) Exit      "
  13.  
  14. #=====================================#
  15. #==============FUNCTIONS==============#
  16. #=====================================#
  17.  
  18. #defines menu
  19. def menu(parameter):
  20.     print "     +==============+"
  21.     print "     |  CONVERSIONS |"
  22.     print "     |     MENU     |"
  23.     print "     |==============|"
  24.     for word in parameter:
  25.         print "     |%s|" % word
  26.         print "     |--------------|"
  27.  
  28. #defines algorithm for Lb to Kg    
  29. def lb2kg(var, weight):
  30.     kilograms = (weight / var)
  31.     print "%s lbs is %s kgs" % (weight, kilograms)
  32.  
  33. #defines algorithm for Kg to Lb
  34. def kg2lb(var, weight):
  35.     lbs = (weight * var)
  36.     print "%s kgs is %s lbs" % (weight, lbs)
  37.  
  38. #=====================================#
  39. #=============MAIN PROGRAM============#
  40. #=====================================#
  41.  
  42. def main():
  43.     menu(menus)
  44.     choice = input("Please make a selection(1-3): ")
  45.    
  46.     if choice == 1:
  47.         lb2kg(var, weight)
  48.     elif choice == 2:
  49.         ks2lb(var, weight)
  50.     elif choice == 3:
  51.         print "Exiting Program. Goodbye"
  52.         return
  53.     else:
  54.         print "Invalid Selection"
  55.         return main()
Add Comment
Please, Sign In to add comment