AP Computer Science Principles Flashcards: Program Function And Purpose

Study Program Function And Purpose in AP Computer Science Principles with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science Principles

Program Function And Purpose

0 mastered0 still learning

0% Complete

QUESTION
1/ 69

Identify the error: def divide(a, b): return a/b; divide(5,0)

Tap card or press Space to flip

ANSWER

Division by zero error. Cannot divide by zero in mathematics.

How well did you know it?

Card 1 / 69

What this deck covers

This deck focuses on Program Function And Purpose, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science Principles.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: Identify the error: def divide(a, b): return a/b; divide(5,0)

Answer: Division by zero error. Cannot divide by zero in mathematics.

Flashcard 2: Identify the output: f = lambda x: x + 1; print(f(5))

Answer:

  1. Lambda function adds 1 to input 5.

Flashcard 3: Find and correct: def square(x): return x**; print(square(4))

Answer: Replace x** with x**2. Exponentiation operator requires complete expression.

Flashcard 4: Which keyword is used to define a function in Python?

Answer: def. Standard Python keyword for function declaration.

Flashcard 5: What is an anonymous function?

Answer: A function defined without a name, often using lambda. Lambda creates functions without explicit naming.

Flashcard 6: Find the error: def increment(x): x+=1; return x; increment()

Answer: Missing argument in increment(). Function call requires one argument but none provided.

Flashcard 7: What is the purpose of function documentation?

Answer: To describe how the function works and its parameters. Documentation explains usage, parameters, and behavior.

Flashcard 8: What is an argument in the context of functions?

Answer: A value passed to a function when it's called. Arguments are actual values sent to functions.

Flashcard 9: Differentiate between a function and a method.

Answer: A method is a function that belongs to an object. Methods are functions bound to specific objects.

Flashcard 10: Which keyword is used to define a function in Python?

Answer: def. Standard Python keyword for function declaration.

Flashcard 11: What are side effects in a function?

Answer: Changes made by a function that affect outside state. Functions modify variables or system state externally.

Flashcard 12: What does 'modularity' mean in a programming context?

Answer: Breaking down a program into separate functions. Organization strategy using independent, focused functions.

Flashcard 13: What is the output: def g(): return 10; print(g())

Answer:

  1. Function returns literal value 10.

Flashcard 14: Identify the output: def f(x): return x+2; print(f(3))

Answer:

  1. Function adds 2 to input 3, returning 5.

Flashcard 15: Find and correct: def square(x): return x**; print(square(4))

Answer: Replace x** with x**2. Exponentiation operator requires complete expression.

Flashcard 16: Identify the output: def h(): pass; print(h())

Answer: None. Empty function returns None by default.

Flashcard 17: What are side effects in a function?

Answer: Changes made by a function that affect outside state. Functions modify variables or system state externally.

Flashcard 18: Identify the error: def add(a, b): return a + b; add(1)

Answer: Missing one argument in add(1). Function requires two parameters but only receives one.

Flashcard 19: What does 'DRY' stand for in programming?

Answer: Don't Repeat Yourself. Principle promoting code reusability and maintenance.

Flashcard 20: Identify the error: def divide(a, b): return a/b; divide(5,0)

Answer: Division by zero error. Cannot divide by zero in mathematics.

Flashcard 21: What is a higher-order function?

Answer: A function that takes another function as an argument. Functions that operate on other functions.

Flashcard 22: What is a pure function?

Answer: A function with no side effects and consistent output. Pure functions have predictable, isolated behavior.

Flashcard 23: Identify the output: def f(x): return x*x; print(f(4))

Answer:

  1. Function squares input value 4.

Flashcard 24: Find the error: def multiply(x): return x*y; multiply(2,3)

Answer: y is undefined in multiply. Variable y is not defined in function scope.

Flashcard 25: What is the purpose of variable scope?

Answer: To define where a variable can be accessed. Scope controls variable visibility and access.

Flashcard 26: What does 'first-class functions' mean?

Answer: Functions treated as first-class citizens, assignable to variables. Functions can be stored, passed, and manipulated.

Flashcard 27: What is a global variable?

Answer: A variable defined outside functions, accessible by all. Global variables exist throughout program execution.

Flashcard 28: What is the main purpose of a function in programming?

Answer: To encapsulate reusable code logic. Functions group related code into reusable blocks.

Flashcard 29: What is the purpose of a function prototype?

Answer: To declare the function's signature before its definition. Prototypes declare function interface before implementation.

Flashcard 30: What is a local variable?

Answer: A variable defined within a function, accessible only there. Scope restricts access to function's internal area.

Flashcard 31: What is the purpose of comments in a function?

Answer: To explain code functionality for human readers. Comments improve code readability and maintenance.

Flashcard 32: Identify the output: def f(x): return x-1; print(f(0))

Answer: -1. Function subtracts 1 from input 0.

Flashcard 33: What is the output: def g(): return 10; print(g())

Answer:

  1. Function returns literal value 10.

Flashcard 34: Differentiate between a function and a method.

Answer: A method is a function that belongs to an object. Methods are functions bound to specific objects.

Flashcard 35: What is the purpose of comments in a function?

Answer: To explain code functionality for human readers. Comments improve code readability and maintenance.

Flashcard 36: Identify the output: def square(x): return x**2; print(square(3))

Answer:

  1. Function squares input value 3.

Flashcard 37: What is the purpose of a default parameter value?

Answer: To provide a fallback value if no argument is passed. Defaults handle optional parameters gracefully.

Flashcard 38: What is a parameter in a function?

Answer: A variable used to pass information into a function. Parameters act as placeholders for function inputs.

Flashcard 39: Identify the output: def sum(a, b): return a+b; print(sum(3,4))

Answer:

  1. Function adds two arguments together.

Flashcard 40: Identify the output: def m(x=5): return x; print(m())

Answer:

  1. Function uses default parameter value 5.

Flashcard 41: What does 'modularity' mean in a programming context?

Answer: Breaking down a program into separate functions. Organization strategy using independent, focused functions.

Flashcard 42: What is a function's signature?

Answer: The function's name and its parameter list. Identifies function uniquely by name and parameters.

Flashcard 43: What is a parameter in a function?

Answer: A variable used to pass information into a function. Parameters act as placeholders for function inputs.

Flashcard 44: What is the purpose of a function prototype?

Answer: To declare the function's signature before its definition. Prototypes declare function interface before implementation.

Flashcard 45: Identify the output: def m(x=5): return x; print(m())

Answer:

  1. Function uses default parameter value 5.

Flashcard 46: What is the purpose of variable scope?

Answer: To define where a variable can be accessed. Scope controls variable visibility and access.

Flashcard 47: What is function overloading?

Answer: Defining multiple functions with the same name but different parameters. Same name functions with different parameter signatures.

Flashcard 48: Identify the output: def h(): pass; print(h())

Answer: None. Empty function returns None by default.

Flashcard 49: What is recursion in programming?

Answer: A function calling itself to solve a problem. Self-reference enables solving complex problems iteratively.

Flashcard 50: What is the purpose of the return statement in a function?

Answer: To send back a result from the function. Return transfers computed values back to caller.

Flashcard 51: What is the purpose of function documentation?

Answer: To describe how the function works and its parameters. Documentation explains usage, parameters, and behavior.

Flashcard 52: Identify the output: def f(x): return x+2; print(f(3))

Answer:

  1. Function adds 2 to input 3, returning 5.

Flashcard 53: What is an argument in the context of functions?

Answer: A value passed to a function when it's called. Arguments are actual values sent to functions.

Flashcard 54: What is recursion in programming?

Answer: A function calling itself to solve a problem. Self-reference enables solving complex problems iteratively.

Flashcard 55: Find the error: def multiply(x): return x*y; multiply(2,3)

Answer: y is undefined in multiply. Variable y is not defined in function scope.

Flashcard 56: Identify the error: def add(a, b): return a + b; add(1)

Answer: Missing one argument in add(1). Function requires two parameters but only receives one.

Flashcard 57: Identify the output: def sum(a, b): return a+b; print(sum(3,4))

Answer:

  1. Function adds two arguments together.

Flashcard 58: Identify the output: def f(x): return x-1; print(f(0))

Answer: -1. Function subtracts 1 from input 0.

Flashcard 59: What is a global variable?

Answer: A variable defined outside functions, accessible by all. Global variables exist throughout program execution.

Flashcard 60: Identify the output: def f(x): return x**3; print(f(2))

Answer:

  1. Function cubes input value 2.

Flashcard 61: What is the main purpose of a function in programming?

Answer: To encapsulate reusable code logic. Functions group related code into reusable blocks.

Flashcard 62: What is the purpose of the return statement in a function?

Answer: To send back a result from the function. Return transfers computed values back to caller.

Flashcard 63: What is an anonymous function?

Answer: A function defined without a name, often using lambda. Lambda creates functions without explicit naming.

Flashcard 64: Identify the output: f = lambda x: x + 1; print(f(5))

Answer:

  1. Lambda function adds 1 to input 5.

Flashcard 65: What is a function's signature?

Answer: The function's name and its parameter list. Identifies function uniquely by name and parameters.

Flashcard 66: What is a local variable?

Answer: A variable defined within a function, accessible only there. Scope restricts access to function's internal area.

Flashcard 67: Find the error: def increment(x): x+=1; return x; increment()

Answer: Missing argument in increment(). Function call requires one argument but none provided.

Flashcard 68: What is the purpose of a default parameter value?

Answer: To provide a fallback value if no argument is passed. Defaults handle optional parameters gracefully.

Flashcard 69: Identify the output: def square(x): return x**2; print(square(3))

Answer:

  1. Function squares input value 3.