Python Program to Convert Celsius to Fahrenheit

In this Python program, we will convert temperature values from Celsius to Fahrenheit. The Celsius and Fahrenheit scales are two common temperature scales used around the world. Converting Celsius to Fahrenheit involves a simple mathematical formula.

Problem Statement

Given a temperature value in Celsius, we need to convert it to the corresponding value in Fahrenheit.

Python Program to Convert Celsius to Fahrenheit

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


# Test the program
celsius = float(input("Enter the temperature in Celsius: "))
fahrenheit = celsius_to_fahrenheit(celsius)

print(f"Temperature in Fahrenheit: {fahrenheit}°F")

How It Works

  1. The function celsius_to_fahrenheit(celsius) takes a temperature value in Celsius as input and returns the corresponding temperature value in Fahrenheit.
  2. The conversion formula from Celsius to Fahrenheit is: F = (C * 9/5) + 32, where F represents Fahrenheit and C represents Celsius.
  3. We apply the formula to the input Celsius value and store the result in the variable fahrenheit.
  4. Finally, we return fahrenheit, which represents the temperature value in Fahrenheit.

Input/Output

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this python tutorial, you will learn how to Display Prime Numbers Between Two Intervals using the if and else...
In this python tutorial, you will learn how to Calculate Standard Deviation with built in functions of the python programming...
Merge Sort is a popular sorting algorithm that follows the divide-and-conquer paradigm to efficiently sort an array or list of...