Write a program to Convert Celsius To Fahrenheit in Python
# Python Program to convert temperature in celsius to fahrenheit
# To take celsius from the user
celsius= float(input("Enter value in celsius"))
# calculate fahrenheit
fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))
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
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
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”