Advertisement
Guest User

Cooking Converter Project V1.0

a guest
Dec 18th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1.  
  2. # Cooking Converter Project V1.0
  3. # <ha>import antigravity http://xkcd.com/353/</ha>
  4.  
  5. while True: # clear the screen
  6.     if sys.platform.startswith('win'):
  7.         import os
  8.         os.system('cls')
  9.         break
  10.     elif sys.platform.startswith('linux'):
  11.         import os
  12.         os.system('clear')
  13.         break
  14.  
  15. print "What is the amount you are converting from?"
  16. in_amount = int(raw_input(">"))
  17.  
  18. print "\nWhat is the unit you are converting from:"
  19. print "gram | tbsp | tsp | ml | lt | oz | pnt | cup | qrt | gal? "
  20. in_unit = raw_input(">")
  21.  
  22. print "\nFinally, what is the unit you are converting to:"
  23. print "gram | tbsp | tsp | ml | lt | oz | pnt | cup | qrt | gal? "
  24. out_unit = raw_input(">")
  25.  
  26.  
  27. # all related to the gram
  28. # volmul = volume_unit_multiplier
  29. def convert(in_amount, in_unit, out_unit):
  30.     volmul = {
  31.         'gram': 1,
  32.         'tbsp': 14.8,
  33.         'tsp' : 4.2,
  34.         'ml'  : 1,
  35.         'lt'  : 1000.,
  36.         'pnt' : 473.2,
  37.         'cup' : 236.5,
  38.         'qrt' : 946.3,
  39.         'gal' : 3785,
  40.         'oz'  : 28.34
  41. }
  42.     return in_amount*volmul[in_unit]/volmul[out_unit]
  43.  
  44. print "\n%.2f %s\n" % (convert(in_amount, in_unit, out_unit), out_unit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement