Program No.
-1
Write a menu driven program to convert the given temperature from fahrenheit to celcius
and vice versa depending upon user's choice.
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5.0/9.0
def celsius_to_fahrenheit(celsius):
return (celsius * 9.0/5.0) + 32
def main():
while True:
print("\nTemperature Conversion Menu:")
print("1. Fahrenheit to Celsius")
print("2. Celsius to Fahrenheit")
print("3. Exit")
choice = input("Enter your choice (1/2/3): ")
if choice == '1':
fahrenheit = float(input("Enter temperature in Fahrenheit: "))
print(f"{fahrenheit}°F is equal to {fahrenheit_to_celsius(fahrenheit)}°C")
elif choice == '2':
celsius = float(input("Enter temperature in Celsius: "))
print(f"{celsius}°C is equal to {celsius_to_fahrenheit(celsius)}°F")
elif choice == '3':
print("Exiting the program. Goodbye!")
break
else:
print("Invalid choice. Please enter 1, 2 or 3.")
if __name__ == "__main__":
main()
Output:
Temperature Conversion Menu:
1. Fahrenheit to Celsius
2. Celsius to Fahrenheit
3. Exit
Enter your choice (1/2/3):