Write a temperature converter program that uses lambda functions to convert from Fahrenheit to Celsius and vice versa.
ctf = lambda c:9/5*c+32
ftc = lambda f:((f-32)*5)/9
Flag=1
while(Flag):
print("\n\nPress 1 to convert degree C to degree Farenhite: ")
print("Press 2 to convert degree Farenhite to degree C: ")
print("Press 0 to QUIT")
Flag = int(input("Enter Option (0/1/2): "))
if(Flag==1):
c=int(input("Enter Temperature in (C):"))
f = ctf(c)
if(Flag==2):
c=int(input("Enter Temperature in (F):"))
c = ftc(f)
print("\nTemperature in (F) : %.1f"%f)
print("Temperature in (C) : %.1f"%c)
Comments
Leave a comment