BeginnerCoder

Lesson 7 — Functions

Reusable blocks

A function packages code under a name so you can run it again and again by "calling" it. It can take inputs (parameters) and hand back a result with return.

Why it matters: functions keep code short, organised and easy to fix — write the logic once, reuse it everywhere.

Watch out: return sends a value back to the caller; print() only shows it. They are not the same.

Want it another way?
Task

Write add(a, b) that returns a + b, so the last line prints 5.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.