Project: work out your average
Python · Unit 1: First steps
- Free
- Python
- Project
- 2 exercises
A function is code with a name that you can use whenever you want.
You create it with def, it receives data inside parentheses and hands over its result with return.
What goes inside is indented: 4 spaces.
def double(n):
return n * 2
print(double(4))Prints
8
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Complete the code
Fill in the function so it hands over triple the number.
def triple(n): ___ n * 32. Write the code
Write the function
average(a, b, c)that gives back the average of three grades. For example,average(8, 9, 10)gives 9.def average(a, b, c): # Replace pass with a return pass
Do this lesson
See all lessons →It opens in your browser. It is free and you do not need an account to start.