Programming Fundamentals/Functions/Python3
Appearance
(Redirected from Computer Programming/Subroutines/Python3)
functions.py
[edit | edit source]# This program asks the user for a Fahrenheit temperature,
# converts the given temperature to Celsius,
# and displays the results.
#
# References:
# https://www.mathsisfun.com/temperature-conversion.html
# https://en.wikibooks.org/wiki/Python_Programming
def get_fahrenheit():
print("Enter Fahrenheit temperature:")
fahrenheit = float(input())
return fahrenheit
def calculate_celsius(fahrenheit):
celsius = (fahrenheit - 32) * 5 / 9
return celsius
def display_result(fahrenheit, celsius):
print(str(fahrenheit) + "° Fahrenheit is " +
str(celsius) + "° Celsius")
def main():
fahrenheit = get_fahrenheit()
celsius = calculate_celsius(fahrenheit)
display_result(fahrenheit, celsius)
main()
Try It
[edit | edit source]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
- InterviewBit
- paiza.IO
- Programiz
- PythonTutor
- Python Fiddle
- repl.it
- RexTester
- Trinket
- TutorialsPoint
- Python Online
- Python Playground
- LabEx
- Python-Fiddle
- Python Sandbox