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. Why it matters Procedures are how programmers manage complexity. They let you: - Reuse logic instead of duplicating it. - Name an idea so code reads like its intent. - Hide detail behind a clean interface, the heart of

Challenge: Rectangle Stats