Python Program to Convert Celsius To Fahrenheit1 min read

Write a program to Convert Celsius To Fahrenheit in Python


The code you provided is a simple Python program that converts temperature in Celsius to Fahrenheit.

The program starts by using the input() function to prompt the user to enter a temperature value in Celsius. The user’s input is stored as a string, so it needs to be converted to a float using the float() function. The variable celsius is then assigned the value input by the user.

Next, the program calculates the equivalent temperature in Fahrenheit by using the formula (celsius * 1.8) + 32 and assigns the result to the variable fahrenheit.

Finally, the program uses the print() function to output the equivalent temperature in Fahrenheit to the console. The % operator is used to format the output and insert the value of celsius and fahrenheit into the string that is passed to the print() function. The %0.1f within the string is a format specifier, it tells Python to format the number as a floating-point number with 1 decimal place.

The output will depend on the input provided by the user, for example if the user inputs 30, the output will be “30.0 degree Celsius is equal to 86.0 degree Fahrenheit”

Leave a Comment