cook.py
cookunknown
plain_text
20 days ago
7.4 kB
5
Indexable
def teaspoons_to_tablespoons(teaspoons): return teaspoons * 1 / 3 def cups_to_milliliters(cups): return cups * 240 def cups_to_tablespoons(cups): return cups * 16 def fluid_ounces_to_milliliters(ounces): return ounces * 29.5735 def cook(): print("\n" + "="*50) print(" Cooking Measurement Conversions ".center(50, "=")) print("="*50) print("[1] Teaspoons to Tablespoons") print("[2] Cups to Milliliters") print("[3] Cups to Tablespoons") print("[4] Fluid Ounces to Milliliters") print("[5] Return to Main Menu") print("="*50) def cook_tsp_tbsp(): while True: try: print("\n" + "="*50) cooking_select = input("Enter an option (1-5): \n-- ") print("="*50) if not cooking_select.isdigit(): print("="*50) print(" INVALID INPUT! Please enter a numeric value. ") print("="*50) continue cooking_select = int(cooking_select) match cooking_select: case 1: while True: tsp_to_tbsp = input("\n[Teaspoons to Tablespoons Conversion] \nEnter Teaspoon/s: ") if not tsp_to_tbsp.replace(".", "", 1).isdigit(): print("="*50) print(" INVALID INPUT! Please enter a numeric value. ") print("="*50) continue tsp_to_tbsp = float(tsp_to_tbsp) print(f"{tsp_to_tbsp} Teaspoon/s is {teaspoons_to_tablespoons(tsp_to_tbsp):.2f} Tablespoon/s!") while True: back = input("\n[1] Choose another option \n[2] Stay \n[3] Return to Main Menu\n-- ") if back.isdigit(): back = int(back) if back == 1: return elif back == 2: break elif back == 3: print("\nReturning to Main menu...") return "RETURN_MAIN" else: print("="*50) print(" Invalid entry, Please choose 1, 2, or 3. ") print("="*50) case 2: while True: cup_to_mil = input("\n[Cups to Milliliters Conversion]\nEnter Cup/s: ") if not cup_to_mil.replace(".", "", 1).isdigit(): print("="*50) print(" INVALID INPUT! Please enter a numeric value. ") print("="*50) continue cup_to_mil = float(cup_to_mil) print(f"{cup_to_mil} Cup/s is {cups_to_milliliters(cup_to_mil):.2f} Milliliters/s!") while True: back = input("\n[1] Choose another option \n[2] Stay \n[3] Return to Main Menu\n-- ") if back.isdigit(): back = int(back) if back == 1: return elif back == 2: break elif back == 3: print("\nReturning to Main menu...") return "RETURN_MAIN" else: print("="*50) print(" Invalid entry, Please choose 1, 2, or 3. ") print("="*50) case 3: while True: cup_to_tbsp = input("\n[Cups to Tablespoons Conversion]\nEnter Cup/s: ") if not cup_to_tbsp.replace(".", "", 1).isdigit(): print("="*50) print(" INVALID INPUT! Please enter a numeric value. ") print("="*50) continue cup_to_tbsp = float(cup_to_tbsp) print(f"{cup_to_tbsp} Cup/s is {cups_to_tablespoons(cup_to_tbsp):.2f} Tablespoon/s!") while True: back = input("\n[1] Choose another option \n[2] Stay \n[3] Return to Main Menu\n-- ") if back.isdigit(): back = int(back) if back == 1: return elif back == 2: break elif back == 3: print("\nReturning to Main menu...") return "RETURN_MAIN" else: print("="*50) print(" Invalid entry, Please choose 1, 2, or 3. ") print("="*50) case 4: while True: ounces_to_mil = input("\n[Fluid Ounces to Milliliters Conversion]\nEnter Fluid Ounce/s: ") if not ounces_to_mil.replace(".", "", 1).isdigit(): print("="*50) print(" INVALID INPUT! Please enter a numeric value. ") print("="*50) continue ounces_to_mil = float(ounces_to_mil) print(f"{ounces_to_mil} Fluid Ounce/s is {fluid_ounces_to_milliliters(ounces_to_mil):.2f} Milliliter/s!") while True: back = input("\n[1] Choose another option \n[2] Stay \n[3] Return to Main Menu\n-- ") if back.isdigit(): back = int(back) if back == 1: return elif back == 2: break elif back == 3: print("\nReturning to Main menu...") return "RETURN_MAIN" else: print("="*50) print(" Invalid entry, Please choose 1, 2, or 3. ") print("="*50) case 5: print("\nReturning to main menu...") return "RETURN_MAIN" case _: print("="*50) print(" Enter a valid selection (1-5) ") print("="*50) except ValueError: print("="*50) print(" INVALID INPUT! Enter a numeric value only. ") print("="*50)
Editor is loading...
Leave a Comment