< Object-Oriented Programming < Introduction
variables.py
"""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 It
Copy and paste the code above into one of the following free online development environments or use your own Python3 compiler / interpreter / IDE.
- GDB Online
- Ideone
- paiza.IO
- Programiz
- PythonTutor
- Python Fiddle
- repl.it
- RexTester
- Trinket
- TutorialsPoint
See Also
- Computer Programming
- Python Programming
- Wikibooks: Python Programming
- Wikibooks: Non-Programmer's Tutorial for Python 3
- Python For Everybody - P4E
This article is issued from Wikiversity. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.