This article will explain the conversion of Celsius to Fahrenheit in python. Both these are units of temperature.
Celsius(or centigrade) can be converted to Fahrenheit using below formula

F = C * 9/5 + 32

or

F = C * 1.8 + 32

Algorithm
Celsius can be converted to Fahrenheit using below steps.
1. Read Celsius temperature as input from keyboard and store it in a variable.
2. Multiply it by 9 and divide the result by 5 or you can straightaway multiply the input value by 1.8.
3. Add 32 to the result of above step to get the converted value in Fahrenheit.
Python code
Python program written as per above steps follows.

#read input in celsius 
temp_cel = float(input('Enter temperature in Celsius'))
# convert to fahrenheit using formula
temp_ft = (temp_cel * 1.8) +32
# display result
print('Temperature in Fahrenheit is %0.1f'%temp_ft)

Here input() function is used for reading user input in python. This function reads input in string format, so it is converted to a numeric format using float() function.
If your program shall deal with integers, you can use int() function to convert input value to an integer.

Also, print() function is used for printing output in python. Also note the %0.1f format specifier, this is used for printing the result to 1 decimal place as evident from the following program output.

Enter temperature in Celsius 34.5
Temperature in Fahrenheit is 94.1

If you do not care about decimal places, simply use the below statement

print('Temperature in Fahrenheit is', temp_ft)

Hope the post was helpful, do not forget to hit the clap.

0

Share your thoughts !!

Close Menu

Never Miss an article !

Get the new post delivered straight into your inbox, enter your email and hit the button

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

codippa will use the information you provide on this form to be in touch with you and to provide updates and marketing.