Write a temperature converter program that uses lambda functions to convert from Fahrenheit to Celsius and vice versa.
# Python temperature converter program that uses lambda functions to convert from Fahrenheit to Celsius and vice versa.
celciusToFahrenheit = lambda c: 9 / 5 * c + 32
fahrenheitToCelcius = lambda f: ((f - 32) * 5) / 9
choice = 1
while choice:
print("Please select an option\n")
print("1- to convert degree Celsius to degree Fahrenheit")
print("2- to convert degree Fahrenheit to degree Celsius")
print("0- to quit")
choice = int(input("Enter your option: "))
if choice == 1:
c = int(input("Enter Temperature in degrees Celsius:"))
f = celciusToFahrenheit(c)
print("\nTemperature in degrees Fahrenheit is : %.1f" % f)
if choice == 2:
f = int(input("Enter Temperature in Fahrenheit:"))
c = fahrenheitToCelcius(f)
print("\nTemperature in degrees Celsius is : %.1f" % c)
Comments
Leave a comment