Python Tutorials

Python Programs

Python Convert Celsius to Fahrenheit


Python Convert Celsius to Fahrenheit

In this tutorial, we will learn how to convert a temperature from Celsius to Fahrenheit in Python. We will cover the formula used for the conversion and implement it in a Python function.


What is Temperature Conversion

Temperature conversion is the process of changing the temperature value from one unit of measurement to another. The Celsius and Fahrenheit scales are the most commonly used temperature scales. The formula to convert Celsius to Fahrenheit is:

F = C × 9/5 + 32


Syntax

The syntax to convert Celsius to Fahrenheit in Python is:

def celsius_to_fahrenheit(celsius):
    return celsius * 9/5 + 32


Converting Celsius to Fahrenheit

We can create a function to convert a given Celsius temperature to Fahrenheit.

For example,

  1. Define a function named celsius_to_fahrenheit that takes one parameter celsius.
  2. Use the formula F = C × 9/5 + 32 to convert the Celsius temperature to Fahrenheit.
  3. Return the converted Fahrenheit temperature.
  4. Call the function with a sample Celsius value and print the result.

Python Program

def celsius_to_fahrenheit(celsius):
    return celsius * 9/5 + 32

# Convert 25 degrees Celsius to Fahrenheit
fahrenheit = celsius_to_fahrenheit(25)

# Print the converted temperature
print('25 degrees Celsius is equal to', fahrenheit, 'degrees Fahrenheit')

Output

25 degrees Celsius is equal to 77.0 degrees Fahrenheit