Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Convert Celsius To Fahrenheit using Python?
In this article, we will show you how to convert Celsius To Fahrenheit using Python.
Celsius
Celsius is a temperature measurement unit that is also known as centigrade. It is an SIderived unit that is used by the majority of countries throughout the world.
It is named after the Swedish astronomer Anders Celsius.
Fahrenheit
Fahrenheit is a temperature scale named after the Polish-born German physicist Daniel Gabriel Fahrenheit, and it uses degrees Fahrenheit as a temperature unit.
To obtain Fahrenheit equivalent of celsius, multiply by 1.8 and add 32 -
f=c*1.8+32
Or we can use another formula ?
f=(c*9/5)+32
Converting Celsius To Fahrenheit using the first formula f=c*1.8+32
Algorithm (Steps)
Following are the Algorithm/steps to be followed to perform the desired task ?
Create a variable to store the input celsius degree temperature.
Use the mathematical formula f=c*1.8+32 to convert the input celsius degree temperature to Fahrenheit degree temperature.
Print the Fahrenheit equivalent of the given input celsius degree temperature.
Example
The following program converts the given input celsius degree temperature to Fahrenheit degree temperature using the formula f=c*1.8+32 ?
<div class="execute"></div><div class="code-mirror language-python" contenteditable="plaintext-only" spellcheck="false" style="outline: none; overflow-wrap: break-word; overflow-y: auto; white-space: pre-wrap;"><span class="token comment"># input celsius degree temperature</span> celsius_temp <span class="token operator">=</span> <span class="token number">45</span> <span class="token comment"># converting celsius degree temperature to Fahrenheit</span> fahrenheit_temp <span class="token operator">=</span>celsius_temp<span class="token operator">*</span><span class="token number">1.8</span><span class="token operator">+</span><span class="token number">32</span> <span class="token comment"># printing the Fahrenheit equivalent of the given input celsius degree</span> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"The Fahrenheit equivalent of 45 celsius = "</span><span class="token punctuation">,</span> fahrenheit_temp<span class="token punctuation">)</span> </div><div class="output-wrapper"><div class="console-close"></div><div class="code-output"></div></div>
Output
On executing, the above program will generate the following output ?
The Fahrenheit equivalent of 45 celsius = 113.0
Converting Celsius To Fahrenheit using f=(c*9/5)+32
Algorithm (Steps)
Following are the Algorithm/steps to be followed to perform the desired task ?
Create a variable to store the input celsius degree temperature.
Use the mathematical formula f=(c*9/5)+32 to convert the input celsius degree temperature to Fahrenheit degree temperature.
Print the Fahrenheit equivalent of the given input celsius degree temperature.
Example
The following program converts the given input celsius degree temperature to Fahrenheit degree temperature using the formula f=(c*9/5)+32 ?
<div class="execute"></div><div class="code-mirror language-python" contenteditable="plaintext-only" spellcheck="false" style="outline: none; overflow-wrap: break-word; overflow-y: auto; white-space: pre-wrap;"><span class="token comment"># input celsius degree temperature</span> celsius_temp <span class="token operator">=</span> <span class="token number">45</span> <span class="token comment"># converting celsius degree temperature to Fahrenheit</span> fahrenheit_temp <span class="token operator">=</span> <span class="token punctuation">(</span>celsius_temp<span class="token operator">*</span><span class="token number">9</span><span class="token operator">/</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token number">32</span> <span class="token comment"># printing the Fahrenheit equivalent of celsius</span> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"The Fahrenheit equivalent of 45 celsius = "</span><span class="token punctuation">,</span> fahrenheit_temp<span class="token punctuation">)</span> </div><div class="output-wrapper"><div class="console-close"></div><div class="code-output"></div></div>
Output
On executing, the above program will generate the following output ?
The Fahrenheit equivalent of 45 celsius = 113.0
Converting Celsius To Fahrenheit using User Defined Function
Algorithm (Steps)
Following are the Algorithm/steps to be followed to perform the desired task ?
Create a function convertCelsiustoFahrenheit(), which converts the given celsius degree temperature to Fahrenheit degree temperature
Use the mathematical formula f=(c*9/5)+32 to convert the passed celsius degree temperature to Fahrenheit degree temperature to the function.
Return Fahrenheit degree temperature of passed celsius temperature.
Create a variable to store the input celsius degree temperature.
Call the convertCelsiustoFahrenheit() function by passing the input celsius as an argument.
Print the Fahrenheit equivalent of the given celsius degree temperature
Example
The following program converts the given input celsius degree temperature to Fahrenheit degree temperature using the user-defined function and formula f=(c*9/5)+32 ?
<div class="execute"></div><div class="code-mirror language-python" contenteditable="plaintext-only" spellcheck="false" style="outline: none; overflow-wrap: break-word; overflow-y: auto; white-space: pre-wrap;"><span class="token comment"># creating a function that converts the given celsius degree temperature</span> <span class="token comment"># to Fahrenheit degree temperature</span> <span class="token keyword">def</span> <span class="token function">convertCelsiustoFahrenheit</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token comment"># converting celsius degree temperature to Fahrenheit degree temperature</span> f <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token number">9</span><span class="token operator">/</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token operator">*</span>c <span class="token operator">+</span> <span class="token number">32</span> <span class="token comment"># returning Fahrenheit degree temperature of given celsius temperature</span> <span class="token keyword">return</span> <span class="token punctuation">(</span>f<span class="token punctuation">)</span> <span class="token comment"># input celsius degree temperature</span> celsius_temp <span class="token operator">=</span> <span class="token number">80</span> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"The input Temperature in Celsius is "</span><span class="token punctuation">,</span>celsius_temp<span class="token punctuation">)</span> <span class="token comment"># calling convertCelsiustoFahrenheit() function by passing</span> <span class="token comment"># the input celsius as an argument</span> fahrenheit_temp <span class="token operator">=</span> convertCelsiustoFahrenheit<span class="token punctuation">(</span>celsius_temp<span class="token punctuation">)</span> <span class="token comment"># printing the Fahrenheit equivalent of the given celsius degree temperature</span> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"The Fahrenheit equivalent of input celsius degree = "</span><span class="token punctuation">,</span> fahrenheit_temp<span class="token punctuation">)</span> </div><div class="output-wrapper"><div class="console-close"></div><div class="code-output"></div></div>
Output
On executing, the above program will generate the following output ?
The input Temperature in Celsius is 80 The Fahrenheit equivalent of input celsius degree = 176.0
Conclusion
We learned what celsius temperature is and Fahrenheit temperature is in this article. We also learned how to convert them using mathematical formulas. We also learned how to write a user-defined function that takes a Celsius temperature as an argument, transforms it to Fahrenheit, and returns it.
