Python Exercise: Convert temperatures to and from celsius, fahrenheit
2. Temperature Converter
Write a Python program to convert temperatures to and from Celsius and Fahrenheit.
Python: Centigrade and Fahrenheit Temperatures :
The centigrade scale, which is also called the Celsius scale, was developed by Swedish astronomer Andres Celsius. In the centigrade scale, water freezes at 0 degrees and boils at 100 degrees. The centigrade to Fahrenheit conversion formula is:
Fahrenheit and centigrade are two temperature scales in use today. The Fahrenheit scale was developed by the German physicist Daniel Gabriel Fahrenheit . In the Fahrenheit scale, water freezes at 32 degrees and boils at 212 degrees.
C = (5/9) * (F - 32)
where F is the Fahrenheit temperature. You can also use this Web page to convert Fahrenheit temperatures to centigrade. Just enter a Fahrenheit temperature in the text box below, then click on the Convert button.

Sample Solution:
Python Code:
Sample Output:
Input the temperature you like to convert? (e.g., 45F, 102C etc.) : 104f The temperature in Celsius is 40 degrees.
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Python program to convert a list of temperatures in Celsius to Fahrenheit and vice versa, outputting both results side-by-side.
- Write a Python program that accepts a temperature string (e.g., "60C" or "45F") and converts it to the opposite scale.
- Write a Python program to implement temperature conversion using lambda functions and map() for a list of mixed temperature values.
- Write a Python program to validate user input for temperature conversion and re-prompt if the input format is invalid.
Go to:
Previous: Write a Python program to find those numbers which are divisible by 7 and multiple of 5, between 1500 and 2700 (both included).
Next: Write a Python program to guess a number between 1 to 9.
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.