Python Celsius to Fahrenheit

Document 对象参考手册Python3 Examples

The following example demonstrates how to convert Celsius to Fahrenheit:

Example

# -*- coding: UTF-8 -*- # Filename : test.py # author by : www.example.com # User inputs Celsius temperature # Receive user input celsius = float(input('Enter Celsius temperature:')) # Calculate Fahrenheit temperature fahrenheit = (celsius * 1.8) + 32 print('%0.1f Celsius temperature converted to Fahrenheit is %0.1f' %(celsius,fahrenheit))

The output of executing the above code is:

输入摄氏温度: 38
38.0 摄氏温度转为华氏温度为 100.4 

In the above example, the formula for converting Celsius to Fahrenheit is celsius * 1.8 = fahrenheit - 32. Therefore, the following equation is obtained:

celsius = (fahrenheit - 32) / 1.8

Document 对象参考手册Python3 Examples

Other Extensions