Functions and Abstraction
Building with reusable pieces
What is a function?
A function is a named block of code that performs a task. It can take inputs, do work, and often return an output.
Abstraction
Abstraction means hiding unnecessary detail so we can focus on the important idea. Functions are a powerful form of abstraction.
Why functions help
Functions make programs shorter, easier to read, easier to test, and easier to reuse.
What is one major benefit of a function?
Functions package code into reusable parts.
Correct answer: It groups reusable instructions together
What is abstraction in simple words?
Abstraction helps manage complexity.
Correct answer: Focusing on the important parts and hiding unnecessary detail
Function vocabulary
A function that calculates the area of a rectangle is an example of:
The function hides the steps and gives a simpler interface.
Correct answer: Abstraction
Why do programmers use functions instead of repeating code?
Reusing code reduces errors and improves clarity.
Correct answer: To avoid repetition and make code easier to manage