sec_1.py (588B)
1 # Write a menu-driven Python program to convert Fahrenheit to Celsius and Celsius to Fahrenheit based on user choice. 2 3 while True: 4 choice = int(input("\n1. f to c" 5 "\n2. c to f" 6 "\n-1. exit" 7 "\nEnter the choice: ")) 8 if choice == 1: 9 f = float(input("\nEnter the f: ")) 10 c = (f - 32) * 5 / 9 11 print(f"{f} = {c:.2f}c\n") 12 elif choice == 2: 13 c = float(input("Enter the c: ")) 14 f = (c * 9 / 5) + 32 15 print(f"{c} = {f:.2f}f\n") 16 elif choice == -1: 17 break 18 else: 19 print("Wrong choice.\n")