Developing Procedures - AP Computer Science Principles
- What is an argument in procedures?
- Value passed to a procedure's parameter. The actual data passed to parameters when calling.
- State the term for the code block inside a procedure.
- Procedure body. The executable code that implements the procedure's logic.
- What is the term for a procedure without parameters?
- Parameterless procedure. Takes no input values when called.
- Which keyword specifies a procedure's output in Python?
- return. Sends a value back to the caller and exits the function.
- Find the error: def subtract(a, b): print(a - b) return
- No error; syntax is correct. Valid procedure with side effect and empty return.
- What is a default parameter?
- A parameter with a default value. Provides fallback value when argument is not supplied.
- What is a return value in a procedure?
- The output a procedure produces. The result sent back to the calling code.
- What is a callback function?
- A function passed as an argument. Used for event handling and asynchronous programming.
- What is a pure function?
- A function with no side effects. Predictable behavior with no external state changes.
- What is a procedure's signature?
- Its name, parameters, and return type. Defines how to call and use the procedure.
- Identify the error: def greet(): print('Hello') return
- No error; syntax is correct. Valid syntax for procedure with print side effect.
- What is the base case in recursion?
- The condition to stop recursion. Prevents infinite recursion by providing an exit condition.
- What is a lambda function?
- An anonymous, inline function. Concise way to create simple functions inline.
- State the term for input values a procedure uses.
- Parameters. Variables that accept data when the procedure is called.
- Identify the error: def hello(name) print('Hello, ' + name)
- Missing colon after parameters. Function definitions require colon after parameter list.
- Choose the correct type: procedure vs. method
- Method: Bound to an object; Procedure: Not bound. Methods belong to classes; procedures are independent.
- Find the syntax error: def add(a, b): return a + b
- No error; syntax is correct. Valid Python function syntax with proper colon and return.
- What is the term for executing a procedure?
- Procedure invocation. The act of running or calling a procedure.
- Identify the error: def multiply(a, b) return a * b
- Missing colon after parameters. Python requires colon after parameter list in function definitions.
- What is a procedure's name?
- Identifier used to invoke it. Label that distinguishes it from other procedures.
- What is a side effect in procedures?
- An impact beyond returning a value. Changes program state beyond the return value.
- State the term for a procedure that calls itself.
- Recursive procedure. Uses divide-and-conquer by breaking problems into smaller parts.
- Identify the keyword used to define a procedure in Python.
- def. Standard Python syntax for creating function definitions.
- Choose the correct usage: procedure vs. function
- Procedure: No return; Function: Returns value. Functions return values; procedures perform actions.
- What is the purpose of a procedure in programming?
- Encapsulate code for reuse and modularity. Breaks complex programs into manageable, reusable components.
- What is a procedure's postcondition?
- Conditions ensured after execution. Guarantees about the procedure's results or effects.
- Identify the error: def increment(x): x += 1 return x
- No error; syntax is correct. Valid function that modifies and returns parameter.
- What is a procedure's precondition?
- Conditions assumed true before execution. Requirements that must be met before calling.
- Identify the error: def sum(a, b = 5, c)
- Default parameter must be last. Default parameters must come after required parameters.
- State the principle of DRY in programming.
- Do not repeat yourself. Promotes code reuse by avoiding duplicate implementations.
- State the purpose of the 'pass' statement in Python.
- Placeholder for future code. Prevents syntax errors in incomplete code blocks.
- Identify the error: def divide(a, b): return a / b
- No error; syntax is correct. Valid division function with proper return statement.
- Identify the issue: result = multiply(2, 3) print(result)
- No issue; syntax is correct. Valid code that calls function and prints result.
- What does 'def' stand for in Python?
- Define a procedure. Short for 'definition' in function declarations.
- What is the difference between 'return' and 'print'?
- 'return' outputs from a function; 'print' displays. Return sends values; print shows text on screen.
- Find the error in this procedure call: add(2, )
- Missing second argument. Function expects two arguments but only receives one.