The formula is F = C × 9 / 5 + 32. The program reads a number, applies the formula and prints the result.
The program
python
celsius = float(input("Temperature in Celsius: ")) fahrenheit = celsius * 9 / 5 + 32 print(f"{celsius}°C is {fahrenheit}°F")
Typed in this example: 37. Press Run to type your own.
output
Temperature in Celsius: 37 37.0°C is 98.6°F
How it works
float(...)turns the typed text into a number that can have a decimal point, so36.6works as well as37.- Python follows normal maths order: the multiplication and division happen first, then
+ 32.
The other direction
To convert Fahrenheit to Celsius, reverse the steps: subtract 32, then multiply by 5 / 9.
python
fahrenheit = 212 celsius = (fahrenheit - 32) * 5 / 9 print(f"{fahrenheit}°F is {celsius}°C")
output
212°F is 100.0°C
Here the brackets matter: without them, Python would multiply 32 by 5 / 9 first.