Developing Procedures - AP Computer Science Principles

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

Study these flashcards