The Simplest Python Program to Convert Celcius to Fahrenheit
|In this Python example, we will learn how to convert temperature from Celsius to Fahrenheit with the help of code. Let’s get started.
1. What is Temperature and the role of Fahrenheit and Celsius?
Temperature is a physical quantity that expresses hot and cold. It is the manifestation of thermal energy, present in all matter, which is the source of the occurrence of heat, a flow of energy, when a body is in contact with another that is colder or hotter. Temperature is measured with a thermometer.
According to Wikipedia.
The temperature on the thermometer is mentioned in the degree Fahrenheit as well as Celsius.
With the help of Python, we will implement a program to convert the degree Celsius to Degree Fahrenheit.
To convert the Celcius into Fahrenheit, we must use one formula, which is:
Formula:
Temperature_fahrenheit = (Temperature_celsius * 1.8) + 32
Before deep-diving into the topic, some of the topics which may be beneficial for understanding the program implementation better are:
2. How to Convert Temperature Celsius into Temperature Fahrenheit ?
In the program, we will take input from the user for temperature in Celsius value and we will apply the formula to output the Fahrenheit value.
Let’s understand the implementation.
#Python Program to convert Celcius to Fahrenheit temp_celsius = int(input("Enter temperature in Degree Celsius: ")) # Temperature in fahrenheit formula temp_fahrenheit = (temp_celsius * 1.8) + 32 print(temp_celsius,"degree Celsius is equal to %0.1f degree Fahrenheit" %(temp_fahrenheit))
Output Enter temperatur in Degree Celsius: 56 56 degree Celsius is equal to 132.8 degree Fahrenheit
Let’s implement the same program using a simple function.
#Python Program to convert Celcius to Fahrenheit using Function def convert_temp(temp_celsius): return (temp_celsius * 1.8) + 32 temp_celsius = int(input("Enter temperature in Degree Celsius: ")) print(temp_celsius,"degree Celsius is equal to %0.1f degree Fahrenheit" %(convert_temp(temp_celsius)))
Output Enter temperature in Degree Celsius: 45 45 degree Celsius is equal to 113.0 degree Fahrenheit
3. Conclusion
In this article, we discussed how to convert the temperature from degree Celsius to degree Fahrenheit in Python using two different ways.
Helpful Links
Please follow the Python tutorial series or the menu in the sidebar for the complete tutorial series.
Also for examples in Python and practice please refer to Python Examples.
Complete code samples are present on Github project.
Recommended Books
An investment in knowledge always pays the best interest. I hope you like the tutorial. Do come back for more because learning paves way for a better understanding
Do not forget to share and Subscribe.
Happy coding!! ?