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