The Celsius temperature scale defines that water freezes at zero degrees and boils at 100 degrees. This scale is commonly used in many countries around the globe. Despite that fact, the United States continues to use the Fahrenheit scale. The mathematical formula for the conversion between degrees of Celsius (C) and Fahrenheit (F) is as follows: F=(9/5) * C +32. Python is a modern, high-level programming language. It allows you to write a simple four-line script to convert the temperature to Fahrenheit.
Use the "input" function to accept the temperature value in Celsius:
C=input ("Enter the Temperature in Celsius: ")
This command produces the message ("Enter the Temperature in Celsius: ") and require you to input a value; this value is assigned to the variable "C."
Divide 9 by 5 and assign the result to the variable "coefficient" using the command;
coefficient = 9.0/5.0
Multiply the temperature by the variable "coefficient" and add 32 to calculate Fahrenheit; then assign the result to the variable "F:" F=C* coefficient + 32
Output the result using the print statement;
print "Temperature in Fahrenheit is ", F
For example, if you enter the temperature of 30 Celsius the output is "Temperature in Fahrenheit is 86.0."
How to Use Functions in Python
The function is the most fundamental way of abstracting a task in modern programming languages. Any code that is repeated more than...
How to Convert Celsius to Fahrenheit in C++
Fahrenheit is the temperature scale that is used in the United States and in a few other countries. The rest of the...