Project: unit converter
Python · Unit 4: Functions
- Full plan
- Python
- Project
- 2 exercises
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. 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. Write the code
Write
convert(temp, to="F"). Iftois "F", hand back the degrees in Fahrenheit; if it is "C", in Celsius. Use the two functions that are already there.
Do this lesson
See all lessons →It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.