Table of Contents
Python code|Convert Celsius to Fahrenheit
In this article, we will discuss the concept of the Python code|Convert Celsius to Fahrenheit
In this post, we will learn how to write a program to Convert from Celsius into Fahrenheit and display the result on the screen. Here, we have four methods and explain how to calculate Fahrenheit using the given Celsius value and display the result on the screen in Python programming language.
Code to Celsius into Fahrenheit
Convert Celsius into Fahrenheit -#1
In this program, the user declares two variables as Celsius and Fahrenheit and initiates the value as 67.5 to the variable- Celsius. The scientific equation will convert it from Celsius into Fahrenheit in the Python programming language.
Program 1
# Python program to convert temperature in Celsius to Fahrenheit celsius=67.5 #Declare and initialize variables #Calculate Fahrenheit fahrenheit=(celsius*1.8)+32 #print result print('%0.1f degree Celsius is equal to %0.1f degrees Fahrenheit' %(celsius,fahrenheit))
When the above code is executed, it produces the following result
67.5 degree Celsius is equal to 153.5 degrees Fahrenheit
Convert Celsius into Fahrenheit -Entered by the user-#2
In this program, the user declares two variables as Celsius and Fahrenheit. The program asks for input from the user to Celsius then the input will convert from Celsius into Fahrenheit in the Python programming language using the scientific equation.
Program 2
# Python program to convert temperature in Celsius to Fahrenheit celsius=float(input("Enter temperature in Celsius ")) #Ask input from the user #Calculate Fahrenheit fahrenheit=(celsius*1.8)+32 #Ptint result print('%0.1f degree Celsius is equal to %0.1f degrees Fahrenheit' %(celsius,fahrenheit))
When the above code is executed, it produces the following result
Enter temperature in Celsius 100.00
100.0 degree Celsius is equal to 212.0 degrees Fahrenheit
Convert Celsius into Fahrenheit -Using function-#3
In this program, the user declares a double variable as a parameter for Celsius(c) in the user-defined function. When the user runs the program (when calling the function), the value for Celsius passes as an argument to the function.
Finally, the Fahrenheit value is calculated and displayed on the screen using the scientific equation in the Python programming language..
Program 3
# Python program to convert temperature in Celsius to Fahrenheit #uaing user-defined function def convertCelsToFahre(c):#user defined function #Calculate the temperature of Fahrenheit f=(c*1.8)+32 return f celsius=90.00 #Declare and initialize variables #Calling the function fahrenheit=convertCelsToFahre(celsius) print('%0.1f degree Celsius is equal to %0.1f degrees Fahrenheit ' %(celsius,fahrenheit))
When the above code is executed, it produces the following result
90.0 degree Celsius is equal to 194.0 degrees Fahrenheit
Convert Celsius into Fahrenheit Using the function-Entered by the user-#4
In this program, the user declares a double variable as a parameter for Celsius(c) in the user-defined function. When the user runs the program (when calling the function), The program asks for input from the user for Celsius and the value for Celsius passes as an argument to the function.
Finally, the Fahrenheit value is calculated and displayed on the screen using the scientific equation in the Python programming language..
Program 4
# Python code to convert temperature in Celsius to Fahrenheit #uaing user defined function def convertCelsToFahre(c):#user defined function #Calculate temperature Fahrenheit f=(c*1.8)+32 return f celsius=float(input("Enter temperature in Celsius ")) #Ask input from the user #Calling the function fahrenheit=convertCelsToFahre(celsius) print('%0.1f degree Celsius is equal to %0.1f degrees Fahrenheit ' %(celsius,fahrenheit))
When the above code is executed, it produces the following result
Enter temperature in Celsius 101 101.0 degree Celsius is equal to 213.8 degrees Fahrenheit
Similar post
Celsius into Fahrenheit in the C program
Fahrenheit into Celsius in C program
Celsius into Fahrenheit in C++ program
Fahrenheit into Celsius in C++ program
Celsius into Fahrenheit in the C# program
Fahrenheit into Celsius in C# program
Convert Celsius into Fahrenheit in Python
Convert Fahrenheit into Celsius in Python