Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- while True:
- print("teaspoons (0), tablespoons (1), fluid ounces (2), cups (3), pints (4), quarts (5), gallons (6)")
- choice = input ("Please enter the measurement you are looking for: ")
- if choice == "0" or choice == "teaspoons":
- while True:
- try:
- n = input("How many Teaspoons: ")
- n = float(n)
- convert_tea(n)
- break #allows you to break out of a loop if a condition is met
- except ValueError:
- print("No valid measurement! Please try again ...")
- if choice == "1" or choice == "tablespoons":
- while True:
- try:
- n = input("How many Tablespoons: ")
- n = float(n)
- convert_table(n)
- break #allows you to break out of a loop if a condition is met
- except ValueError:
- print("No valid measurement! Please try again ...")
- if (convertAgain()):
- break
- if choice == "2" or choice == "fluid ounces":
- while True:
- try:
- n = input("How many Fluid ounces: ")
- n = float(n)
- convert_ounces(n)
- break #allows you to break out of a loop if a condition is met
- except ValueError:
- print("No valid measurement! Please try again ...")
- if choice == "3" or choice == "cups":
- while True:
- try:
- n = input("How many Cups: ")
- n = float(n)
- convert_cups(n)
- break #allows you to break out of a loop if a condition is met
- except ValueError:
- print("No valid measurement! Please try again ...")
- if choice == "4" or choice == "pints":
- while True:
- try:
- n = input("How many Pints: ")
- n = float(n)
- convert_pints(n)
- break #allows you to break out of a loop if a condition is met
- except ValueError:
- print("No valid measurement! Please try again ...")
- if choice == "5" or choice == "quarts":
- while True:
- try:
- n = input("How many Quarts: ")
- n = float(n)
- convert_quarts(n)
- break #allows you to break out of a loop if a condition is met
- except ValueError:
- print("No valid measurement! Please try again ...")
- if choice == "6" or choice == "gallons":
- while True:
- try:
- n = input("How many Gallons: ")
- n = float(n)
- convert_gallons(n)
- break #allows you to break out of a loop if a condition is met
- except ValueError:
- print("No valid measurement! Please try again ...")
- if (convertAgain()):
- break
- def convertAgain():
- while True:
- yn = input("Would you like to convert something else? ")
- yn = yn.strip()
- yn = yn.lower()
- if yn == "n" or yn =="no":
- return False
- elif yn == "y" or yn == "yes":
- return True
- else:
- print("try again")
- # Teaspoon convsersion
- def convert_tea(x):
- tea = x * 1.0
- table = x / 3.0
- ounces = x / 6.0
- cups = x / 48.0
- pints = x / 96.0
- quarts = x / 192.0
- gallons = x / 768.0
- print("teaspoons", tea)
- print("tablespoons", table)
- print("fluid ounces", ounces)
- print("cups", cups)
- print("pints", pints)
- print("quarts", quarts)
- print("galoons", gallons)
- # Tablespoons conversion
- def convert_table(x):
- tea = x * 3.0
- table = x * 1.0
- ounces = x / 2.0
- cups = x / 16.0
- pints = x / 32.0
- quarts = x / 64.0
- gallons = x / 256.0
- print("teaspoons", tea)
- print("tablespoons", table)
- print("fluid ounces", ounces)
- print("cups", cups)
- print("pints", pints)
- print("quarts", quarts)
- print("galoons", gallons)
- #Fluid ounces conversions
- def convert_ounces(x):
- tea = x * 6.0
- table = x * 2.0
- ounces = x * 1.0
- cups = x / 8.0
- pints = x / 16.0
- quarts = x / 32.0
- gallons = x / 64.0
- print("teaspoons", tea)
- print("tablespoons", table)
- print("fluid ounces", ounces)
- print("cups", cups)
- print("pints", pints)
- print("quarts", quarts)
- print("galoons", gallons)
- #Cups conversions
- def convert_cups(x):
- tea = x * 48.0
- table = x * 16.0
- ounces = x * 8.0
- cups = x * 1.0
- pints = x / 2.0
- quarts = x / 4.0
- gallons = x / 16.0
- print("teaspoons", tea)
- print("tablespoons", table)
- print("fluid ounces", ounces)
- print("cups", cups)
- print("pints", pints)
- print("quarts", quarts)
- print("galoons", gallons)
- #Pints conversions
- def convert_pints(x):
- tea = x * 96.0
- table = x * 32.0
- ounces = x * 16.0
- cups = x * 2.0
- pints = x * 1.0
- quarts = x / 2.0
- gallons = x / 8.0
- print("teaspoons", tea)
- print("tablespoons", table)
- print("fluid ounces", ounces)
- print("cups", cups)
- print("pints", pints)
- print("quarts", quarts)
- print("galoons", gallons)
- #Quarts conversions
- def convert_quarts(x):
- tea = x * 192.0
- table = x * 64.0
- ounces = x * 32.0
- cups = x * 4.0
- pints = x * 2.0
- quarts = x * 1.0
- gallons = x / 4.0
- print("teaspoons", tea)
- print("tablespoons", table)
- print("fluid ounces", ounces)
- print("cups", cups)
- print("pints", pints)
- print("quarts", quarts)
- print("galoons", gallons)
- #Gallons conversions
- def convert_gallons(x):
- tea = x * 768.0
- table = x * 256.0
- ounces = x * 128.0
- cups = x * 16.0
- pints = x * 8.0
- quarts = x * 4.0
- gallons = x * 1.0
- print("teaspoons", tea)
- print("tablespoons", table)
- print("fluid ounces", ounces)
- print("cups", cups)
- print("pints", pints)
- print("quarts", quarts)
- print("galoons", gallons)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement