Procedures and Parameters
Defining and Calling Procedures
Part of: Variables, Lists & Procedures
As programs grow, copying the same block of code in five places becomes a maintenance nightmare. A procedure (called a function in Python) solves this: you write a named, reusable chunk of logic once and call it whenever you need it. Defining and calling. def defines the procedure; greet() runs it. This is abstraction : the caller uses the name and does not care how the body works. Parameters and arguments. Procedures get flexible when you pass data in. A parameter is a placeholder named in the definition; an argument is the actual value you supply at the call. The argument 5 is copied into the parameter num for that one call. Different arguments produce different behavior from the same code. Multiple parameters. A procedure can take several parameters, matched by position: Order matters: the first argument fills the first parameter, the second fills the second, and so on. The AP pseudocode equivalent is PROCEDURE rectangleArea(width, height), same idea of named inputs. What usually goes wrong. What you see What caused it How to fix it --- --- --- Every line prints None The procedure body still ends at pass, so nothing is handed back to the caller Replace pass with an explicit retu
Challenge: Rectangle Stats