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