Applied Programming/Variables/Python3

variables.pyEdit

"""This program converts a Fahrenheit temperature to Celsius.

Input:
    Fahrenheit temperature

Output:
    Fahrenheit temperature
    Celsius temperature

Example:
    Enter Fahrenheit temperature:
     100
    100.0° Fahrenheit is 37.8° Celsius

TODO:
    * All statements are currently global.
    * Functions will be added in a future release.
    
References:
    * http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
    * http://www.mathsisfun.com/temperature-conversion.html

"""

TEMPERATURE_DIFFERENCE = 32
TEMPERATURE_RATIO = 5 / 9

print("Enter Fahrenheit temperature:")
fahrenheit = float(input())

celsius = (fahrenheit - TEMPERATURE_DIFFERENCE) * TEMPERATURE_RATIO

print(f'{fahrenheit:.1f}° Fahrenheit is {celsius:.1f}° Celsius')

Try ItEdit

Copy and paste the code above into one of the following free online development environments or use your own Python3 compiler / interpreter / IDE.

See AlsoEdit