How to Write a Python Program to Convert Celsius to Fahrenheit?

Estimated read time 1 min read

To write a Python program to convert Celsius to Fahrenheit, you can use the following formula:

F = (C * 9/5) + 32

Here’s an example program:

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

fahrenheit = (celsius * 9/5) + 32

print("Temperature in Fahrenheit: ", fahrenheit)

In this program, the float(input("Enter temperature in Celsius: ")) line prompts the user to enter a temperature in Celsius, which is then converted to a floating-point number using the float() function.

The conversion formula (celsius * 9/5) + 32 is used to calculate the equivalent temperature in Fahrenheit. The result is stored in the fahrenheit variable.

Finally, the program prints the temperature in Fahrenheit using the print() function.

Here’s an example output:

Enter temperature in Celsius: 25
Temperature in Fahrenheit:  77.0

The temperature in Celsius (25) is converted to Fahrenheit (77) according to the conversion formula.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply