Wednesday, 14 December 2016

To convert Fahrenheit into Celsius or vice versa

print("enter choice 'c' to convert  fahrenheit  to Celsius")
print("enter choice 'f' to  convert Celsius  to  fahrenheit ")


#to accept choice of user
ch=input('enter choice(c/f):')

#to accept temperature from user
t=float(input('enter temperature:'))


if ch=='c':
    #to convert  fahrenheit  into Celsius
    cel = (t-32)*5/9
    print(' fahrenheit :',t,'\n','Celsius:',cel)
elif ch=='f':
    #to convert Celsius into  fahrenheit
    far=(t*9/5)+32
    print('Celsius:',t,'\n',' fahrenheit :',far)
else:
    #if choice is other than 'c' or 'f' display invalid choice
    print("invalid choice")


OUTPUT :

No comments:

Post a Comment