Temperature often needs to be converted between different scales. In this article, we'll explore how to convert Celsius to Fahrenheit and Fahrenheit to Celsius using Python.
Celsius and Fahrenheit are two different measuring units to use to measure temperature. Celsius unit is widely used around the world, especially in scientific contexts where Fahrenheit is primarily used in the United States, its territories and associated states, and the Bahamas.
The formula to convert Celsius (C) to Fahrenheit (F) is given by:
- F = C x 9/5 + 32
The formula to convert Fahrenheit (F) to Celsius (C) is given by:
- C = 5/9 x (F - 32)
Python Program to Convert Celsius to Fahrenheit.
In this Python program, we are going to take the value of Celsius from the user and then we will use the formula F = (C * 9/5) + 32 to calculate the value of Fahrenheit.
Python Code:
# Temperature in celsius degree celsius = float(input("Enter temperature in Celsius: ")) # Converting the celsius to # fehrenheit using the formula fahrenheit = (celsius * 9/5) + 32 # printing the result print('%.2f Celsius is equivalent to: %.2f Fahrenheit'% (celsius, fahrenheit))
Enter temperature in Celsius: 100 100.00 Celsius is equivalent to: 212.00 Fahrenheit
Python Program to Convert Fahrenheit to Celsius.
Here in this Python program, we are going to take the value of Fahrenheit as input from the user. We will then use the formula C = 5/9 * (F - 32) to convert the temperature of Fahrenheit to Celsius.
Python Code:
# Temperature in Fahrenheit degree fahrenheit = float(input("Enter temperature in Fahrenheit: ")) # Converting the Fahrenheit to # Celsius using the formula celsius = 5/9 * (fahrenheit - 32) # printing the result print('%.2f Fahrenheit is equivalent to: %.2f Celsius'% (fahrenheit, celsius))
Enter temperature in Fahrenheit: 212 212.00 Fahrenheit is equivalent to: 100.00 Celsius
So these are the two Python codes to convert temperature from Fahrenheit to Celsius and Celsius to Fahrenheit.

No comments
Post a Comment