• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Dec 13th, 2019 92 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 choice == "0" or choice == "teaspoons":
7.         while True:
8.             try:
9.                 n = input("How many Teaspoons: ")
10.                 n = float(n)
11.                 convert_tea(n)
12.                 break  #allows you to break out of a loop if a condition is met
13.             except ValueError:
14.                 print("No valid measurement! Please try again ...")
15.
16.     if choice  == "1" or choice == "tablespoons":
17.         while True:
18.             try:
19.                 n = input("How many Tablespoons: ")
20.                 n = float(n)
21.                 convert_table(n)
22.                 break  #allows you to break out of a loop if a condition is met
23.             except ValueError:
24.                 print("No valid measurement! Please try again ...")
25.     if (convertAgain()):
26.         break
27.     if choice == "2" or choice == "fluid ounces":
28.         while True:
29.             try:
30.                 n = input("How many Fluid ounces: ")
31.                 n = float(n)
32.                 convert_ounces(n)
33.                 break  #allows you to break out of a loop if a condition is met
34.             except ValueError:
35.                 print("No valid measurement! Please try again ...")
36.
37.
38.     if choice == "3" or choice == "cups":
39.         while True:
40.             try:
41.                 n = input("How many Cups: ")
42.                 n = float(n)
43.                 convert_cups(n)
44.                 break  #allows you to break out of a loop if a condition is met
45.             except ValueError:
46.                 print("No valid measurement! Please try again ...")
47.
48.
49.     if choice == "4" or choice == "pints":
50.         while True:
51.             try:
52.                 n = input("How many Pints: ")
53.                 n = float(n)
54.                 convert_pints(n)
55.                 break  #allows you to break out of a loop if a condition is met
56.             except ValueError:
57.                 print("No valid measurement! Please try again ...")
58.
59.
60.     if choice == "5" or choice == "quarts":
61.         while True:
62.             try:
63.                 n = input("How many Quarts: ")
64.                 n = float(n)
65.                 convert_quarts(n)
66.                 break  #allows you to break out of a loop if a condition is met
67.             except ValueError:
68.                 print("No valid measurement! Please try again ...")
69.
70.     if choice == "6" or choice == "gallons":
71.         while True:
72.             try:
73.                 n = input("How many Gallons: ")
74.                 n = float(n)
75.                 convert_gallons(n)
76.                 break  #allows you to break out of a loop if a condition is met
77.             except ValueError:
78.                 print("No valid measurement! Please try again ...")
79.     if (convertAgain()):
80.         break
81. def convertAgain():
82.    while True:
83.        yn = input("Would you like to convert something else, yes or no? ")
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.

Top