Temperature Conversion – Python Lab Program

This program gets the choice of the user

  • whether to convert from Fahrenheit to Celsius
  • or Celsius to Fahrenheit

then uses IF and ELIF (header) to run the corresponding conversion code within the blocks (suite)

this program also includes an ELSE section to run when an invalid choice is given.

Note: ch=ch.upper() converts the value inside “ch” to UPPER case character.

ch=input("Enter the choice F(for Farenheit to Celcius)\n or C(for Celcius to
Farenheit): ")
ch=ch.upper()
if(ch=='F'):
f=float(input("Enter the Farenheit Value: "))
c=float((f-32)*5/9)
print("Farenheit to Celcius")
print("The Celcius value for the given Farenheit",f," is ",c, "C")
elif (ch=='C'):
c=float(input("Enter the Celcius Value: "))
f=(c*(9/5))+32
print("Celcius to Farenheit")
print("The Farenheit value for the given Celcius",c,"is",f,"F")
else :
print("Invalid Choice")

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.