Python Celsius to Fahrenheit Conversion
The following example shows how to convert Celsius to Fahrenheit:
Example
-- coding: UTF-8 --
Filename : test.py
author by : www.runoob.com
The user enters a Celsius temperature
Receive user input
celsius
=
float
(
input
(
'
Enter the Celsius temperature:
'
)
)
Calculate the Fahrenheit temperature
fahrenheit
=
(
celsius
1.8
)
32
(
'
%0.1f degrees Celsius equals %0.1f degrees Fahrenheit
'
%
(
celsius
,
fahrenheit
)
)
The output of the code above is:
输入摄氏温度: 38
38.0 摄氏温度转为华氏温度为 100.4
In the example above, the formula for converting Celsius to Fahrenheit is celsius * 1.8 = fahrenheit - 32, which gives the following expression:
celsius = (fahrenheit - 32) / 1.8
Python3 Examples