Using Programs with Data - AP Computer Science Principles
Card 1 of 30
Choose the correct way to start a multiline comment in Python.
Choose the correct way to start a multiline comment in Python.
Tap to reveal answer
Use triple quotes: '''comment'''. Triple quotes allow comments spanning multiple lines.
Use triple quotes: '''comment'''. Triple quotes allow comments spanning multiple lines.
← Didn't Know|Knew It →
What is a string in programming?
What is a string in programming?
Tap to reveal answer
A sequence of characters. Text data type enclosed in quotes or apostrophes.
A sequence of characters. Text data type enclosed in quotes or apostrophes.
← Didn't Know|Knew It →
Which keyword defines a function in Python?
Which keyword defines a function in Python?
Tap to reveal answer
'def'. Keyword that declares new function definitions in Python.
'def'. Keyword that declares new function definitions in Python.
← Didn't Know|Knew It →
What is the output of 'print("Hello, World!")'?
What is the output of 'print("Hello, World!")'?
Tap to reveal answer
Hello, World. Print function displays text exactly as written inside quotes.
Hello, World. Print function displays text exactly as written inside quotes.
← Didn't Know|Knew It →
Identify the correct syntax for a Python function call.
Identify the correct syntax for a Python function call.
Tap to reveal answer
function_name(arguments). Parentheses after name pass values to function parameters.
function_name(arguments). Parentheses after name pass values to function parameters.
← Didn't Know|Knew It →
What does 'len()' function return?
What does 'len()' function return?
Tap to reveal answer
The number of items in an object. Built-in function counts elements in sequences and collections.
The number of items in an object. Built-in function counts elements in sequences and collections.
← Didn't Know|Knew It →
What is a 'while' loop used for?
What is a 'while' loop used for?
Tap to reveal answer
To repeat code while a condition is true. While loops continue until condition becomes false.
To repeat code while a condition is true. While loops continue until condition becomes false.
← Didn't Know|Knew It →
Identify the error: 'if x = 10:'
Identify the error: 'if x = 10:'
Tap to reveal answer
Use '==' for comparison, not '='. Assignment operator should be comparison operator for conditions.
Use '==' for comparison, not '='. Assignment operator should be comparison operator for conditions.
← Didn't Know|Knew It →
What is the main difference between a list and a tuple?
What is the main difference between a list and a tuple?
Tap to reveal answer
Lists are mutable; tuples are immutable. Lists can be modified; tuples cannot be changed.
Lists are mutable; tuples are immutable. Lists can be modified; tuples cannot be changed.
← Didn't Know|Knew It →
Which data type is used for true/false values?
Which data type is used for true/false values?
Tap to reveal answer
Boolean. Boolean data type represents logical values: True or False.
Boolean. Boolean data type represents logical values: True or False.
← Didn't Know|Knew It →
What is the purpose of a function in programming?
What is the purpose of a function in programming?
Tap to reveal answer
To encapsulate code for reuse and organization. Functions group code into reusable blocks with optional parameters.
To encapsulate code for reuse and organization. Functions group code into reusable blocks with optional parameters.
← Didn't Know|Knew It →
What does the 'return' statement do in a function?
What does the 'return' statement do in a function?
Tap to reveal answer
It exits the function and optionally returns a value. Return sends a value back to the caller and stops execution.
It exits the function and optionally returns a value. Return sends a value back to the caller and stops execution.
← Didn't Know|Knew It →
Identify the error in the expression: $5 + '3'$
Identify the error in the expression: $5 + '3'$
Tap to reveal answer
Type error: mixing integer and string. Cannot add integer and string directly without type conversion.
Type error: mixing integer and string. Cannot add integer and string directly without type conversion.
← Didn't Know|Knew It →
Choose the correct syntax to declare an integer variable in Python.
Choose the correct syntax to declare an integer variable in Python.
Tap to reveal answer
variable_name = 0. Python uses assignment operator to create variables dynamically.
variable_name = 0. Python uses assignment operator to create variables dynamically.
← Didn't Know|Knew It →
Which operator is used for exponentiation in Python?
Which operator is used for exponentiation in Python?
Tap to reveal answer
'**'. Double asterisk performs mathematical power operations.
'**'. Double asterisk performs mathematical power operations.
← Didn't Know|Knew It →
Which data structure uses key-value pairs?
Which data structure uses key-value pairs?
Tap to reveal answer
Dictionary. Dictionaries map unique keys to corresponding values.
Dictionary. Dictionaries map unique keys to corresponding values.
← Didn't Know|Knew It →
What is the result of $3 // 2$ in Python?
What is the result of $3 // 2$ in Python?
Tap to reveal answer
- Floor division operator returns integer quotient without remainder.
- Floor division operator returns integer quotient without remainder.
← Didn't Know|Knew It →
What is the purpose of the 'if' statement in programming?
What is the purpose of the 'if' statement in programming?
Tap to reveal answer
To execute code conditionally based on a boolean expression. It evaluates the boolean and runs code only when true.
To execute code conditionally based on a boolean expression. It evaluates the boolean and runs code only when true.
← Didn't Know|Knew It →
What does the 'append' method do to a list?
What does the 'append' method do to a list?
Tap to reveal answer
Adds an element to the end of the list. Append method inserts new item at list's final position.
Adds an element to the end of the list. Append method inserts new item at list's final position.
← Didn't Know|Knew It →
Identify the error in this function definition: 'def add(a, b): return a + b'
Identify the error in this function definition: 'def add(a, b): return a + b'
Tap to reveal answer
No error; the function is correct. This function definition follows proper Python syntax rules.
No error; the function is correct. This function definition follows proper Python syntax rules.
← Didn't Know|Knew It →
What is an array?
What is an array?
Tap to reveal answer
A collection of elements identified by index. Arrays store multiple values accessible by numeric position.
A collection of elements identified by index. Arrays store multiple values accessible by numeric position.
← Didn't Know|Knew It →
What is the purpose of a 'for' loop?
What is the purpose of a 'for' loop?
Tap to reveal answer
To iterate over a sequence of items. For loops process each item in collections automatically.
To iterate over a sequence of items. For loops process each item in collections automatically.
← Didn't Know|Knew It →
How is a comment started in Python?
How is a comment started in Python?
Tap to reveal answer
Using '#'. Hash symbol creates single-line comments in Python code.
Using '#'. Hash symbol creates single-line comments in Python code.
← Didn't Know|Knew It →
Identify the component of a loop that determines when it stops.
Identify the component of a loop that determines when it stops.
Tap to reveal answer
Loop condition or termination condition. This boolean expression controls when the loop continues or stops.
Loop condition or termination condition. This boolean expression controls when the loop continues or stops.
← Didn't Know|Knew It →
Identify the error in this loop: 'for i in range(5) print(i)'
Identify the error in this loop: 'for i in range(5) print(i)'
Tap to reveal answer
Missing colon after range(5). Python requires colon after for statement header.
Missing colon after range(5). Python requires colon after for statement header.
← Didn't Know|Knew It →
Which keyword is used to start a loop in Python?
Which keyword is used to start a loop in Python?
Tap to reveal answer
'for' or 'while'. Both keywords create repetitive execution structures in Python.
'for' or 'while'. Both keywords create repetitive execution structures in Python.
← Didn't Know|Knew It →
What is the result of $4 \times (3 + 2)$?
What is the result of $4 \times (3 + 2)$?
Tap to reveal answer
- Order of operations: parentheses first, then multiplication.
- Order of operations: parentheses first, then multiplication.
← Didn't Know|Knew It →
Which data structure uses key-value pairs?
Which data structure uses key-value pairs?
Tap to reveal answer
Dictionary. Dictionaries map unique keys to corresponding values.
Dictionary. Dictionaries map unique keys to corresponding values.
← Didn't Know|Knew It →
Identify the error in 'for i in 5: print(i)'
Identify the error in 'for i in 5: print(i)'
Tap to reveal answer
'range()' is needed to iterate through integers. Cannot iterate directly over integer; range creates sequence.
'range()' is needed to iterate through integers. Cannot iterate directly over integer; range creates sequence.
← Didn't Know|Knew It →
What is an 'else' clause used for?
What is an 'else' clause used for?
Tap to reveal answer
To execute code when an 'if' condition is false. Else provides alternative code path for false conditions.
To execute code when an 'if' condition is false. Else provides alternative code path for false conditions.
← Didn't Know|Knew It →