Programming Fundamentals/Functions/Python3: Difference between revisions

From Wikiversity
Jump to navigation Jump to search
Content deleted Content added
Creating
(No difference)

Revision as of 23:32, 18 January 2017

subroutines.py

# This program asks the user for a Fahrenheit temperature, 
# converts the given temperature to Celsius,
# and displays the results.

def get_f():
    print("Enter Fahrenheit temperature:")
    f = float(input())
    return f

def calculate_c(f):
    c = (f - 32) * 5 / 9
    return c

def display_result(f, c):
    print(str(f) + "° Fahrenheit is " + str(c) + "° Celsius")

# main
f = get_f()
c = calculate_c(f)
display_result(f, c)

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.

See Also