Write a Python Program to Convert Celsius To Fahrenheit

As a Python programmer, you may frequently encounter the need to convert Celsius to Fahrenheit.

In this tutorial, we will provide a simple Python program to convert Celsius to Fahrenheit.


Before we start with the program, let’s briefly discuss the formula for converting Celsius to Fahrenheit.

The formula is as follows:

Fahrenheit = (Celsius * 1.8) + 32

Now that we have the formula, let’s move on to writing the Python program:

# Program to convert Celsius to Fahrenheit

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

# calculate Fahrenheit
fahrenheit = (celsius * 1.8) + 32

print('%%.2f Celsius is: %%0.2f Fahrenheit' %%(celsius, fahrenheit))

In this program, we first take user input for the temperature in Celsius.

The input is taken as a float using the float() function.

Next, we apply the formula to convert Celsius to Fahrenheit and store the result in the variable fahrenheit.

Finally, we use the print() function to display the result.

We use the string formatting method to display the Celsius and Fahrenheit temperatures with two decimal places.


Conclusion

Converting Celsius to Fahrenheit is a simple task that can be easily accomplished using a Python program.

In this tutorial, we provided a simple Python program that can be used to convert Celsius to Fahrenheit.

By using this program, you can quickly and easily convert temperature values between Celsius and Fahrenheit.