length_match.py
Lengthunknown
plain_text
19 days ago
7.3 kB
1
Indexable
def inches_to_centimeters(inches): return inches * 2.54 def centimeters_to_inches(centimeters): return centimeters / 2.54 def feet_to_meters(feet): return feet * 0.3048 def meters_to_feet(meters): return meters / 0.3048 def length(): print("\n" + "="*50) print(" Length Conversions ".center(50, "=")) print("="*50) print("[1] Inches to Centimeters") print("[2] Centimeters to Inches") print("[3] Feet to Meters") print("[4] Meters to Feet") print("[5] Return to Main Menu") print("="*50) def length_inches_cm(): while True: try: print("\n" + "="*50) length_select = input("Enter an option (1-5): \n-- ") print("="*50) if not length_select.isdigit(): print("="*50) print("# INVALID INPUT! Please enter a numeric value. #") print("="*50) continue length_select = int(length_select) match length_select: case 1: while True: inch_to_cm = input("\n[Inches to Centimeters Conversion]\nEnter Inch/es: ") if not inch_to_cm.replace(".", "", 1).isdigit(): print("="*50) print("# INVALID INPUT! Please enter a numeric value. #") print("="*50) continue inch_to_cm = float(inch_to_cm) print(f"{inch_to_cm} Inch/es is {inches_to_centimeters(inch_to_cm):.2f} Centimeter/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: cm_to_inch = input("\n[Centimeters to Inches Conversion]\nEnter Centimeter/s: ") if not cm_to_inch.replace(".", "", 1).isdigit(): print("="*50) print("# INVALID INPUT! Please enter a numeric value. #") print("="*50) continue cm_to_inch = float(cm_to_inch) print(f"{cm_to_inch} Centimeter/s is {centimeters_to_inches(cm_to_inch):.2f} Inch/es!") 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: ft_to_m = input("\n[Feet to Meters Conversion]\nEnter Feet: ") if not ft_to_m.replace(".", "", 1).isdigit(): print("="*50) print("# INVALID INPUT! Please enter a numeric value. #") print("="*50) continue ft_to_m = float(ft_to_m) print(f"{ft_to_m} Feet is {feet_to_meters(ft_to_m):.2f} Meter/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: m_to_ft = input("\n[Meters to Feet Conversion]\nEnter Meter/s: ") if not m_to_ft.replace(".", "", 1).isdigit(): print("="*50) print("# INVALID INPUT! Please enter a numeric value. #") print("="*50) continue m_to_ft = float(m_to_ft) print(f"{m_to_ft} Meter/s is {meters_to_feet(m_to_ft):.2f} Feet!") 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