In previous units, we’ve used built-in functions like print(), len(), and range(). These functions help us reuse a block of code easily. Today, we’ll learn how to create our own functions using def, understand parameters (inputs) and return values (outputs), and see how functions make our programs cleaner and more powerful.
In this unit, students transition from using built-in functions to creating their own. Through clear examples, they will understand how functions allow programmers to “package repeated logic” into reusable, organized code. Students will learn the syntax of the def statement, including function names, parameters, indentation, and return values. They will also explore the difference between print() and return, grasping the full cycle of “input → processing → output.”
By completing hands-on exercises and small projects, students will practice defining functions to perform calculations, conversions, and decisions. The ultimate learning objective is to help students develop structured programming habits, encapsulating logic, improving reusability, and enhancing clarity, as a foundation for later lessons on conditionals, loops, and modular design.
The key focus of this lesson is mastering the basic structure and usage of functions—understanding how to define a function with def, pass parameters, and return results. Students will learn the concept of data flowing through a function: how inputs are processed to produce outputs, and how defining a function differs from calling it.
The main difficulty lies in distinguishing between print() and return. Many beginners assume they are the same, but print() only displays information, while return sends data back to the program for further computation. Another challenging concept is variable scope: variables defined inside a function are local and cannot be accessed outside. Overcoming these challenges will help students think more clearly about how information moves within a program, building a strong foundation for modular programming and problem decomposition.