Lesson 2 of 19 · 2 min
What is a Function and WHY Do We Need One?
Imagine you write a marks-to-grade converter for 500 students. Without functions, you copy-paste the same 10-line formula 500 times. When the passing mark changes from 40 to 45, you must hunt down and edit all 500 copies — and you will miss some. A function is a named, reusable block of code. Write the logic once. Call it from anywhere. Fix it in one place and every call immediately uses the fix.
Three key benefits:
- DRY (Don't Repeat Yourself) — one change fixes all 500 calls
- Readability —
calculate_grade(85)says exactly what it does - Testability — you can test one function in isolation before wiring it in
