Python Program to Convert Celsius to Fahrenheit

In this post, we will learn how to convert Celsius to Fahrenheit using Python Programming language.

To convert celsius to fahrenheit, follow the following steps:

  1. First of all, Multiply the degree Celsius by 9 / 5 or 1.8.
  2. Now, Add 32 to this number.
  3. This gives us the temperature in degree Celsius.

There are various approaches to solve this problem, some of them are listed below:

  1. Using Standard Method
  2. Using Functions

So, without further ado, let’s begin this tutorial.

Python Program to Convert Celsius to Fahrenheit

# Python Program to Convert Celsius to Fahrenheit
celsius = float(input("Enter temperature in Celsius: "))

# Conversion From Celsius to Fahrenheit
fahrenheit = (celsius * 9/5) + 32

# Displaying output
print('%0.1f degree Celsius = %0.1f degree Fahrenheit' %(celsius, fahrenheit))

Output

Enter temperature in Celsius: 37
37.0 degree Celsius = 98.6 degree Fahrenheit

How Does This Program Work ?

celsius = float(input("Enter temperature in Celsius: "))

In this program, the user is asked to enter the temperature in degree Celsius.

# Conversion From Celsius to Fahrenheit
fahrenheit = (celsius * 9/5) + 32

Then, we convert Celsius to Fahrenheit by multiplying Celsius by 9/5 and adding 32 to this number.

print('%0.1f degree Celsius = %0.1f degree Fahrenheit' %(celsius, fahrenheit))

In the end, the result is printed on the screen using print() function.

Python Program to Convert Celsius to Fahrenheit Using Functions

# Python Program to Convert Celsius to Fahrenheit
def celsius_to_fahrenheit(celsius):
    f = (celsius * 9/5) + 32
    return f

# Asking for Input 
celsius = float(input("Enter the temperature in degree Celsius: "))

# Calling the function
fahrenheit = celsius_to_fahrenheit(celsius)

# Displaying output
print('%0.1f Celsius = %0.1f Fahrenheit' %(celsius, fahrenheit))

Output

Enter the temperature in degree Celsius: 34
34.0 Celsius = 93.2 Fahrenheit
def celsius_to_fahrenheit(celsius):
    f = (celsius * 9/5) + 32
    return f

In this program, we have declared a custom function named celsius_to_fahrenheit which returns the temperature in degree Fahrenheit.

Conclusion

I hope after going through this post, you get to know how to convert Celsius to Fahrenheit using Python Programming language.

If you face any difficulty while understanding this program, let us know in the comment section. We will be delighted to help you.

Also Read:

Leave a Comment

Your email address will not be published.