Hướng dẫn c to f python

In the program below, we take a temperature in degree Celsius and convert it into degree Fahrenheit. They are related by the formula:

fahrenheit = celsius * 1.8 + 32

Source Code

# Python Program to convert temperature in celsius to fahrenheit

# change this value for a different result
celsius = 37.5

# calculate fahrenheit
fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))

Output

37.5 degree Celsius is equal to 99.5 degree Fahrenheit

We encourage you to create a Python program to convert Fahrenheit to Celsius on your own using the following formula

celsius = (fahrenheit - 32) / 1.8

In this tutorial, we will learn how to write a python program for converting degree Celsius temperature into degree Fahrenheit temperature.

Celsius:

Celsius is a unit of measurement for temperature, and it is also known as centigrade, and it is SI derived unit used by most of the countries worldwide.

It is named after the Swedish astronomer Anders Celsius.

Fahrenheit:

Fahrenheit is also a temperature scale, and it is named after Polish-born German physicist Daniel Gabriel Fahrenheit, and it uses degrees Fahrenheit as a unit for temperature.

Suppose we have a temperature in degree Celsius, and our task is to convert the value of temperature into the degree Fahrenheit and display it.

Example:

Approach:

We can input the degree Celsius temperature and apply the conversation formula of degree Fahrenheit from degree Celsius and display it on screen. The following is the relationship of degree Celsius and degree Fahrenheit:

T(�Fahrenheit)=(T(�Celsius)*1.8)+32

OR we can write:

T(�Fahrenheit)=(T(�Celsius)*9/5)+32

Example:

Output:

Temperature value in degree Celsius:  34
The 34.00 degree Celsius is equal to: 93.20 Fahrenheit
----OR----
Temperature value in degree Celsius:  23
The 23.00 degree Celsius is equal to: 73.40 Fahrenheit

To Convert Degree Fahrenheit into Degree Celsius:

The user can use the following formula for converting degree Fahrenheit into degree Celsius:

Hướng dẫn c to f python

Example:

Output:

Temperature value in degree Fahrenheit:  113
The 113.00-degree Fahrenheit is equal to: 45.00 Celsius
----OR----
Temperature value in degree Fahrenheit:  234
The 234.00-degree Fahrenheit is equal to: 112.22 Celsius

Conclusion

In this tutorial, we discussed how to write a Python program for converting degree Fahrenheit to degree Celsius and vice versa.


Home / Python Examples / Python Program to Convert Celsius To Fahrenheit and Vice Versa

Nội dung chính

  • Celsius To Fahrenheit and Fahrenheit to Celsius conversion formulas
  • Program to Convert Fahrenheit to Celsius
  • Fahrenheit:
  • To Convert Degree Fahrenheit into Degree Celsius:
  • Python Conditional: Exercise-2 with Solution

In this tutorial, we will write Python programs to convert Celsius To Fahrenheit and Vice Versa.

Celsius To Fahrenheit and Fahrenheit to Celsius conversion formulas

Celsius and Fahrenheit are the measurement units of Temperature. Let’s see the conversion formulas to convert temperature in degree Celsius to degree Fahrenheit and vice versa.

Celsius = (Fahrenheit – 32) * 5/9
Fahrenheit = (Celsius * 9/5) + 32

To understand the following programs, you must have the basic knowledge of following Python concepts:
1. Python Input/Output
2. Python Data Types

In the following program we are taking the input from user, user enters the temperature in Celsius and the program converts the entered value into Fahrenheit using the conversion formula we have seen above.

celsius = float(input("Enter temperature in celsius: "))
fahrenheit = (celsius * 9/5) + 32
print('%.2f Celsius is: %0.2f Fahrenheit' %(celsius, fahrenheit))

Output:

Program to Convert Fahrenheit to Celsius

In the following program user enters the temperature in Fahrenheit and the program converts the entered value into Celsius using the Fahrenheit to Celsius conversion formula.

fahrenheit = float(input("Enter temperature in fahrenheit: "))
celsius = (fahrenheit - 32) * 5/9
print('%.2f Fahrenheit is: %0.2f Celsius' %(fahrenheit, celsius))

Output:

In this tutorial, we will learn how to write a python program for converting degree Celsius temperature into degree Fahrenheit temperature.

Celsius:

Celsius is a unit of measurement for temperature, and it is also known as centigrade, and it is SI derived unit used by most of the countries worldwide.

It is named after the Swedish astronomer Anders Celsius.

Fahrenheit:

Fahrenheit is also a temperature scale, and it is named after Polish-born German physicist Daniel Gabriel Fahrenheit, and it uses degrees Fahrenheit as a unit for temperature.

Suppose we have a temperature in degree Celsius, and our task is to convert the value of temperature into the degree Fahrenheit and display it.

Example:

Approach:

We can input the degree Celsius temperature and apply the conversation formula of degree Fahrenheit from degree Celsius and display it on screen. The following is the relationship of degree Celsius and degree Fahrenheit:

T(�Fahrenheit)=(T(�Celsius)*1.8)+32

OR we can write:

T(�Fahrenheit)=(T(�Celsius)*9/5)+32

Example:

Output:

Temperature value in degree Celsius:  34
The 34.00 degree Celsius is equal to: 93.20 Fahrenheit
----OR----
Temperature value in degree Celsius:  23
The 23.00 degree Celsius is equal to: 73.40 Fahrenheit

To Convert Degree Fahrenheit into Degree Celsius:

The user can use the following formula for converting degree Fahrenheit into degree Celsius:

Example:

Output:

Temperature value in degree Fahrenheit:  113
The 113.00-degree Fahrenheit is equal to: 45.00 Celsius
----OR----
Temperature value in degree Fahrenheit:  234
The 234.00-degree Fahrenheit is equal to: 112.22 Celsius

Conclusion

In this tutorial, we discussed how to write a Python program for converting degree Fahrenheit to degree Celsius and vice versa.


Last update on August 19 2022 21:50:49 (UTC/GMT +8 hours)

Python Conditional: Exercise-2 with Solution

Write a Python program to convert temperatures to and from celsius, fahrenheit.

Python: Centigrade and Fahrenheit Temperatures :

The centigrade scale, which is also called the Celsius scale, was developed by Swedish astronomer Andres Celsius. In the centigrade scale, water freezes at 0 degrees and boils at 100 degrees. The centigrade to Fahrenheit conversion formula is:

Fahrenheit and centigrade are two temperature scales in use today. The Fahrenheit scale was developed by the German physicist Daniel Gabriel Fahrenheit . In the Fahrenheit scale, water freezes at 32 degrees and boils at 212 degrees.

C = (5/9) * (F - 32)

where F is the Fahrenheit temperature. You can also use this Web page to convert Fahrenheit temperatures to centigrade. Just enter a Fahrenheit temperature in the text box below, then click on the Convert button.

Sample Solution:-

Python Code:

temp = input("Input the  temperature you like to convert? (e.g., 45F, 102C etc.) : ")
degree = int(temp[:-1])
i_convention = temp[-1]

if i_convention.upper() == "C":
  result = int(round((9 * degree) / 5 + 32))
  o_convention = "Fahrenheit"
elif i_convention.upper() == "F":
  result = int(round((degree - 32) * 5 / 9))
  o_convention = "Celsius"
else:
  print("Input proper convention.")
  quit()
print("The temperature in", o_convention, "is", result, "degrees.")

Sample Output:

Input the  temperature you like to convert? (e.g., 45F, 102C etc.) : 104f                                     
The temperature in Celsius is 40 degrees. 

Flowchart:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to find those numbers which are divisible by 7 and multiple of 5, between 1500 and 2700 (both included).
Next: Write a Python program to guess a number between 1 to 9.