Skip to the content

Project: unit converter

Python · Unit 4: Functions

You're going to build a temperature converter out of small functions.

Each one does a single conversion and hands back the result with return.

def miles_to_feet(mi):
    return mi * 5280

print(miles_to_feet(3))

Prints

15840

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Write the code

    Write to_fahrenheit(c), which takes degrees Celsius and hands back the Fahrenheit. The formula is multiply by 9, divide by 5 and add 32.

  2. 2. Write the code

    Write convert(temp, to="F"). If to is "F", hand back the degrees in Fahrenheit; if it is "C", in Celsius. Use the two functions that are already there.

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →