return: the function gives back a result
Section 6: FunctionsLesson 6.2 · ⏱ 7 min
def area(w, h):
return w * h
room = area(4, 5)
print("Room area:", room)
print("Big board:", area(10, 2))
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗Room area: 20 Big board: 20

📌 Another example: a function that says yes or no
return True or False, and we use it inside if.
def is_even(n):
return n % 2 == 0
for n in [3, 8]:
if is_even(n):
print(n, "even")
else:
print(n, "odd")
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗3 odd 8 even
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
A square function that returns the square of the number.
👀 Show the solution🙈 Hide the solution
def square(n):
return n * n
print(square(9))
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗81
Result: 81
Medium
An area function that returns a rectangle's area.
👀 Show the solution🙈 Hide the solution
def area(w, h):
return w * h
print(area(4, 6) + area(2, 3))
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗30
Result: 24 + 6 = 30
Hard
A biggest function that returns the biggest number in a list (without max).
👀 Show the solution🙈 Hide the solution
def biggest(nums):
best = nums[0]
for n in nums:
if n > best:
best = n
return best
print(biggest([4, 17, 9, 12]))
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗17
Result: 17

