How to convert Celsius to Fahrenheit in Python

These are the two temperature scales that are most commonly used:

  1. Fahrenheit
  2. Celsius

Celsius vs. Fahrenheit

Most nations use the metric temperature system known as Celsius (symbol: °C). Under typical meteorological circumstances, water has a freezing point of 0 degrees Celsius and a boiling temperature of 100 degrees Celsius, according to the Celsius system. The United States and a few other nations predominantly use the Fahrenheit (symbol: °F) unit of measurement. According to the Fahrenheit scale, under typical climatic circumstances, water has a freezing point of 32 degrees Fahrenheit and a boiling temperature of 212 degrees Fahrenheit.

Celsius to Fahrenheit conversion formula

Using the formula below, we can change the temperature from Celsius to Fahrenheit:

F=(C×95)+32F = \left(C \times \frac{9}{5} \right) + 32

where FF is the Fahrenheit temperature and CC is the Celsius temperature.

Problem statement

We need to apply the formula above to a temperature value that has been provided to convert it from Celsius to Fahrenheit.

Explanation

Let’s suppose we have a temperature of 30 degrees Celsius. Let’s put the value of CC in the formula above,

Given C=30°CC = 30\degree C,

F=(C×95)+32=(30×95)+32=(30×1.8)+32=54+32=86°F\begin{split} F & = \left(C \times \frac{9}{5} \right) + 32 \\ & = \left(30 \times \frac{9}{5} \right) + 32 \\ & = (30 \times 1.8) + 32 \\ & = 54 + 32 \\ & = 86 \degree F \end{split}

Implementation

Let’s see an example of converting a temperature in Celsius to Fahrenheit in Python:

c = 30
# Using formula
f = (c * 9/5) + 32
print("After converting celsius to fahrenheit the value is", f)

Code explanation

Here’s the line-to-line explanation of the code above:

  • Line 1: It declares a variable c with a value of 30.
  • Line 4: It uses the formula to convert the Celsius value to Fahrenheit and store it in the variable f.
  • Line 5: It prints the value of the variable f by displaying a message on the screen.

Free Resources

HowDev By Educative. Copyright ©2025 Educative, Inc. All rights reserved