Temperature Conversion: Celsius and Fahrenheit units in Python
In this Python tutorial, we will learn how to do temperature conversion using Python. Python program to convert temperature from one unit to another is given below.
TEMPERATURE CONVERSION in Python
The Celsius (symbol: °C) is an S.I unit of temperature.
The Fahrenheit (symbol: °F) is a unit of temperature that has prior use to metrication.
The average human body temperature taken with a thermometer in the mouth (or basal body temperature) is 37 ° C or 98.6 ° F.
Let’s take a look into the code snippet.
PROGRAM: Python program to convert Celsius to Fahrenheit and Fahrenheit to Celsius
print("Choose from below options:") print("1.Celsius to Fahrenheit.") print("2.Fahrenheit to Celsius.") o=int(input("option(1/2):")) if(o==1): c=float(input("Temperature in Celsius:")) f=1.8*(c)+32.0 f=round(f,1) #temperature in fahrenheit precise to 1 decimal place print("Temperature in Fahrenheit:",f) elif(o==2): f=float(input("Temperature in Fahrenheit:")) c=(f-32)/1.8 c=round(c,1) #temperature in celsius precise to 1 decimal place print("Temperature in Celsius:",c) else: print("Choose 1 or 2.")
OUTPUT 1:
Choose from below options: 1.Celsius to Fahrenheit. 2.Fahrenheit to Celsius. option(1/2):2 Temperature in Fahrenheit:99 Temperature in Celsius: 37.2
OUTPUT 2:
Choose from below options: 1.Celsius to Fahrenheit. 2.Fahrenheit to Celsius. option(1/2):1 Temperature in Celsius:37 Temperature in Fahrenheit: 98.6
Also Read:
Leave a Reply