SHARE
TWEET

Untitled

a guest Dec 13th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def main():
  2.    
  3.  while True:
  4.     print("teaspoons (0), tablespoons (1), fluid ounces (2), cups (3), pints (4), quarts (5), gallons (6)")
  5.     choice = input ("Please enter the measurement you are looking for: ")
  6.     if (convertAgain()):
  7.         break  
  8.     if choice == "0" or choice == "teaspoons":
  9.         while True:
  10.             try:
  11.                 n = input("How many Teaspoons: ")
  12.                 n = float(n)
  13.                 convert_tea(n)
  14.                 break  #allows you to break out of a loop if a condition is met
  15.             except ValueError:
  16.                 print("No valid measurement! Please try again ...")
  17.            
  18.     if choice  == "1" or choice == "tablespoons":
  19.         while True:
  20.             try:
  21.                 n = input("How many Tablespoons: ")
  22.                 n = float(n)
  23.                 convert_table(n)
  24.                 break  #allows you to break out of a loop if a condition is met
  25.             except ValueError:
  26.                 print("No valid measurement! Please try again ...")
  27.  
  28.     if choice == "2" or choice == "fluid ounces":
  29.         while True:
  30.             try:
  31.                 n = input("How many Fluid ounces: ")
  32.                 n = float(n)
  33.                 convert_ounces(n)
  34.                 break  #allows you to break out of a loop if a condition is met
  35.             except ValueError:
  36.                 print("No valid measurement! Please try again ...")
  37.            
  38.        
  39.     if choice == "3" or choice == "cups":
  40.         while True:
  41.             try:
  42.                 n = input("How many Cups: ")
  43.                 n = float(n)
  44.                 convert_cups(n)
  45.                 break  #allows you to break out of a loop if a condition is met
  46.             except ValueError:
  47.                 print("No valid measurement! Please try again ...")
  48.            
  49.        
  50.     if choice == "4" or choice == "pints":
  51.         while True:
  52.             try:
  53.                 n = input("How many Pints: ")
  54.                 n = float(n)
  55.                 convert_pints(n)
  56.                 break  #allows you to break out of a loop if a condition is met
  57.             except ValueError:
  58.                 print("No valid measurement! Please try again ...")
  59.            
  60.        
  61.     if choice == "5" or choice == "quarts":
  62.         while True:
  63.             try:
  64.                 n = input("How many Quarts: ")
  65.                 n = float(n)
  66.                 convert_quarts(n)
  67.                 break  #allows you to break out of a loop if a condition is met
  68.             except ValueError:
  69.                 print("No valid measurement! Please try again ...")
  70.            
  71.        
  72.     if choice == "6" or choice == "gallons":
  73.         while True:
  74.             try:
  75.                 n = input("How many Gallons: ")
  76.                 n = float(n)
  77.                 convert_gallons(n)
  78.                 break  #allows you to break out of a loop if a condition is met
  79.             except ValueError:
  80.                 print("No valid measurement! Please try again ...")
  81. def convertAgain():
  82.    while True:
  83.        yn = input("Would you like to convert something else? ")
  84.        yn = yn.strip()
  85.        yn = yn.lower()
  86.        if yn == "n" or yn =="no":
  87.            return False
  88.        elif yn == "y" or yn == "yes":
  89.                return True
  90.        else:
  91.            print("try again")
  92.  
  93.  
  94.  # Teaspoon convsersion
  95. def convert_tea(x):
  96.     tea = x * 1.0  
  97.     table = x / 3.0
  98.     ounces = x / 6.0
  99.     cups = x  / 48.0
  100.     pints = x / 96.0
  101.     quarts = x / 192.0
  102.     gallons = x / 768.0
  103.     print("teaspoons", tea)
  104.     print("tablespoons", table)
  105.     print("fluid ounces", ounces)
  106.     print("cups", cups)
  107.     print("pints", pints)
  108.     print("quarts", quarts)
  109.     print("galoons", gallons)
  110.  
  111.          
  112.    
  113.     # Tablespoons conversion
  114. def convert_table(x):
  115.     tea = x  * 3.0
  116.     table = x * 1.0
  117.     ounces = x / 2.0
  118.     cups = x  / 16.0
  119.     pints = x / 32.0
  120.     quarts = x / 64.0
  121.     gallons = x / 256.0
  122.     print("teaspoons", tea)
  123.     print("tablespoons", table)
  124.     print("fluid ounces", ounces)
  125.     print("cups", cups)
  126.     print("pints", pints)
  127.     print("quarts", quarts)
  128.     print("galoons", gallons)
  129.  
  130.     #Fluid ounces conversions
  131. def convert_ounces(x):
  132.     tea = x  * 6.0
  133.     table = x * 2.0
  134.     ounces = x * 1.0
  135.     cups = x  / 8.0
  136.     pints = x / 16.0
  137.     quarts = x / 32.0
  138.     gallons = x / 64.0
  139.     print("teaspoons", tea)
  140.     print("tablespoons", table)
  141.     print("fluid ounces", ounces)
  142.     print("cups", cups)
  143.     print("pints", pints)
  144.     print("quarts", quarts)
  145.     print("galoons", gallons)
  146.    
  147.     #Cups  conversions
  148. def convert_cups(x):
  149.     tea = x  * 48.0
  150.     table = x * 16.0
  151.     ounces = x * 8.0
  152.     cups = x  * 1.0
  153.     pints = x / 2.0
  154.     quarts = x / 4.0
  155.     gallons = x / 16.0
  156.     print("teaspoons", tea)
  157.     print("tablespoons", table)
  158.     print("fluid ounces", ounces)
  159.     print("cups", cups)
  160.     print("pints", pints)
  161.     print("quarts", quarts)
  162.     print("galoons", gallons)    
  163.  
  164.     #Pints conversions    
  165. def convert_pints(x):
  166.     tea = x  * 96.0
  167.     table = x * 32.0
  168.     ounces = x * 16.0
  169.     cups = x  * 2.0
  170.     pints = x * 1.0
  171.     quarts = x / 2.0
  172.     gallons = x / 8.0
  173.     print("teaspoons", tea)
  174.     print("tablespoons", table)
  175.     print("fluid ounces", ounces)
  176.     print("cups", cups)
  177.     print("pints", pints)
  178.     print("quarts", quarts)
  179.     print("galoons", gallons)
  180.    
  181.     #Quarts conversions
  182. def convert_quarts(x):
  183.     tea = x  * 192.0
  184.     table = x * 64.0
  185.     ounces = x * 32.0
  186.     cups = x  * 4.0
  187.     pints = x * 2.0
  188.     quarts = x * 1.0
  189.     gallons = x / 4.0
  190.     print("teaspoons", tea)
  191.     print("tablespoons", table)
  192.     print("fluid ounces", ounces)
  193.     print("cups", cups)
  194.     print("pints", pints)
  195.     print("quarts", quarts)
  196.     print("galoons", gallons)
  197.    
  198.     #Gallons conversions
  199. def convert_gallons(x):
  200.     tea = x  * 768.0
  201.     table = x * 256.0
  202.     ounces = x * 128.0
  203.     cups = x  * 16.0
  204.     pints = x * 8.0
  205.     quarts = x * 4.0
  206.     gallons = x * 1.0
  207.     print("teaspoons", tea)
  208.     print("tablespoons", table)
  209.     print("fluid ounces", ounces)
  210.     print("cups", cups)
  211.     print("pints", pints)
  212.     print("quarts", quarts)
  213.     print("galoons", gallons)        
  214. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top