Program Function and Purpose - AP Computer Science Principles
Card 1 of 30
What is the purpose of variable scope?
What is the purpose of variable scope?
Tap to reveal answer
To define where a variable can be accessed. Scope controls variable visibility and access.
To define where a variable can be accessed. Scope controls variable visibility and access.
← Didn't Know|Knew It →
Identify the output: def f(x): return x+2; print(f(3))
Identify the output: def f(x): return x+2; print(f(3))
Tap to reveal answer
- Function adds 2 to input 3, returning 5.
- Function adds 2 to input 3, returning 5.
← Didn't Know|Knew It →
Find the error: def increment(x): x+=1; return x; increment()
Find the error: def increment(x): x+=1; return x; increment()
Tap to reveal answer
Missing argument in increment(). Function call requires one argument but none provided.
Missing argument in increment(). Function call requires one argument but none provided.
← Didn't Know|Knew It →
Identify the output: def f(x): return x**3; print(f(2))
Identify the output: def f(x): return x**3; print(f(2))
Tap to reveal answer
- Function cubes input value 2.
- Function cubes input value 2.
← Didn't Know|Knew It →
What is function overloading?
What is function overloading?
Tap to reveal answer
Defining multiple functions with the same name but different parameters. Same name functions with different parameter signatures.
Defining multiple functions with the same name but different parameters. Same name functions with different parameter signatures.
← Didn't Know|Knew It →
What is a parameter in a function?
What is a parameter in a function?
Tap to reveal answer
A variable used to pass information into a function. Parameters act as placeholders for function inputs.
A variable used to pass information into a function. Parameters act as placeholders for function inputs.
← Didn't Know|Knew It →
Which keyword is used to define a function in Python?
Which keyword is used to define a function in Python?
Tap to reveal answer
def. Standard Python keyword for function declaration.
def. Standard Python keyword for function declaration.
← Didn't Know|Knew It →
What is the purpose of the return statement in a function?
What is the purpose of the return statement in a function?
Tap to reveal answer
To send back a result from the function. Return transfers computed values back to caller.
To send back a result from the function. Return transfers computed values back to caller.
← Didn't Know|Knew It →
Identify the error: def add(a, b): return a + b; add(1)
Identify the error: def add(a, b): return a + b; add(1)
Tap to reveal answer
Missing one argument in add(1). Function requires two parameters but only receives one.
Missing one argument in add(1). Function requires two parameters but only receives one.
← Didn't Know|Knew It →
What is a function's signature?
What is a function's signature?
Tap to reveal answer
The function's name and its parameter list. Identifies function uniquely by name and parameters.
The function's name and its parameter list. Identifies function uniquely by name and parameters.
← Didn't Know|Knew It →
What is the purpose of the return statement in a function?
What is the purpose of the return statement in a function?
Tap to reveal answer
To send back a result from the function. Return transfers computed values back to caller.
To send back a result from the function. Return transfers computed values back to caller.
← Didn't Know|Knew It →
Identify the error: def add(a, b): return a + b; add(1)
Identify the error: def add(a, b): return a + b; add(1)
Tap to reveal answer
Missing one argument in add(1). Function requires two parameters but only receives one.
Missing one argument in add(1). Function requires two parameters but only receives one.
← Didn't Know|Knew It →
What is the purpose of function documentation?
What is the purpose of function documentation?
Tap to reveal answer
To describe how the function works and its parameters. Documentation explains usage, parameters, and behavior.
To describe how the function works and its parameters. Documentation explains usage, parameters, and behavior.
← Didn't Know|Knew It →
What is the purpose of variable scope?
What is the purpose of variable scope?
Tap to reveal answer
To define where a variable can be accessed. Scope controls variable visibility and access.
To define where a variable can be accessed. Scope controls variable visibility and access.
← Didn't Know|Knew It →
What are side effects in a function?
What are side effects in a function?
Tap to reveal answer
Changes made by a function that affect outside state. Functions modify variables or system state externally.
Changes made by a function that affect outside state. Functions modify variables or system state externally.
← Didn't Know|Knew It →
What is the purpose of comments in a function?
What is the purpose of comments in a function?
Tap to reveal answer
To explain code functionality for human readers. Comments improve code readability and maintenance.
To explain code functionality for human readers. Comments improve code readability and maintenance.
← Didn't Know|Knew It →
Identify the output: def f(x): return x-1; print(f(0))
Identify the output: def f(x): return x-1; print(f(0))
Tap to reveal answer
-1. Function subtracts 1 from input 0.
-1. Function subtracts 1 from input 0.
← Didn't Know|Knew It →
Which keyword is used to define a function in Python?
Which keyword is used to define a function in Python?
Tap to reveal answer
def. Standard Python keyword for function declaration.
def. Standard Python keyword for function declaration.
← Didn't Know|Knew It →
What is the main purpose of a function in programming?
What is the main purpose of a function in programming?
Tap to reveal answer
To encapsulate reusable code logic. Functions group related code into reusable blocks.
To encapsulate reusable code logic. Functions group related code into reusable blocks.
← Didn't Know|Knew It →
Identify the output: f = lambda x: x + 1; print(f(5))
Identify the output: f = lambda x: x + 1; print(f(5))
Tap to reveal answer
- Lambda function adds 1 to input 5.
- Lambda function adds 1 to input 5.
← Didn't Know|Knew It →
What is a function's signature?
What is a function's signature?
Tap to reveal answer
The function's name and its parameter list. Identifies function uniquely by name and parameters.
The function's name and its parameter list. Identifies function uniquely by name and parameters.
← Didn't Know|Knew It →
What is recursion in programming?
What is recursion in programming?
Tap to reveal answer
A function calling itself to solve a problem. Self-reference enables solving complex problems iteratively.
A function calling itself to solve a problem. Self-reference enables solving complex problems iteratively.
← Didn't Know|Knew It →
Identify the output: def square(x): return x**2; print(square(3))
Identify the output: def square(x): return x**2; print(square(3))
Tap to reveal answer
- Function squares input value 3.
- Function squares input value 3.
← Didn't Know|Knew It →
Identify the output: def f(x): return x+2; print(f(3))
Identify the output: def f(x): return x+2; print(f(3))
Tap to reveal answer
- Function adds 2 to input 3, returning 5.
- Function adds 2 to input 3, returning 5.
← Didn't Know|Knew It →
Identify the output: def m(x=5): return x; print(m())
Identify the output: def m(x=5): return x; print(m())
Tap to reveal answer
- Function uses default parameter value 5.
- Function uses default parameter value 5.
← Didn't Know|Knew It →
What is a parameter in a function?
What is a parameter in a function?
Tap to reveal answer
A variable used to pass information into a function. Parameters act as placeholders for function inputs.
A variable used to pass information into a function. Parameters act as placeholders for function inputs.
← Didn't Know|Knew It →
Identify the output: def sum(a, b): return a+b; print(sum(3,4))
Identify the output: def sum(a, b): return a+b; print(sum(3,4))
Tap to reveal answer
- Function adds two arguments together.
- Function adds two arguments together.
← 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 and consistent output. Pure functions have predictable, isolated behavior.
A function with no side effects and consistent output. Pure functions have predictable, isolated behavior.
← Didn't Know|Knew It →
What is an anonymous function?
What is an anonymous function?
Tap to reveal answer
A function defined without a name, often using lambda. Lambda creates functions without explicit naming.
A function defined without a name, often using lambda. Lambda creates functions without explicit naming.
← Didn't Know|Knew It →
What is the output: def g(): return 10; print(g())
What is the output: def g(): return 10; print(g())
Tap to reveal answer
- Function returns literal value 10.
- Function returns literal value 10.
← Didn't Know|Knew It →