Font size
WorksheetsAP CSP Midterm Exam Review
Total questions: 50
Worksheet time: 26mins
What terminates this iteration?
When i equals j.
When userMax equals i.
When userMax is less than 0.
When userMax is greater than 10.
When does the Boolean in the if-else statement evaluate to false?
When userMax is greater than 0.
When userMax is less than 0.
When userMax is equal to 0.
When userMax is less than 1.
What is the point of calling the userInputSeq procedure inside the if-statement’s block of code?
To reset the userMax variable.
To display the sum of the numbers.
To prompt the user to enter a valid number.
To terminate the loop.
What role does the variable `n` play in the procedure? How would the code be different if there wasn’t a parameter?
`n` determines the number of times the message is displayed; without `n`, the message would display once.
`n` determines the message content; without `n`, the message would be empty.
`n` determines the display order; without `n`, the order would be reversed.
`n` determines the display speed; without `n`, the message would display slowly.
Which statement is NOT true?
2 MOD 4 = 0
15 MOD 2 = 1
17 MOD 3 = 2
25 MOD 4 = 1
Given the procedure call `getAnyNumber(5, 20)`, what is the maximum possible value for `getNum`?
5
15
19
20
Explain the functionality check of the if-else control structure in version B of getAnyNumber:
It only generates a random number when num1 and num2 are equal
It only generates a random number when num1 and num2 are not equal
What is displayed after the procedure call list1(numList)?
[2, 3, 4, 5, 6, 7]
[20, 30, 40, 50, 60, 70]
[2, 30, 4, 50, 6, 70]
[20, 3, 40, 5, 60, 7]
Given numList is storing [2, 3, 4, 5, 6, 7] and we are using AP CSP Pseudocode, what does numList look like after inserting number 1 at index 1?
[1, 2, 3, 4, 5, 6, 7]
[2, 1, 3, 4, 5, 6, 7]
[2, 3, 4, 5, 6, 7, 1]
[2, 3, 4, 1, 5, 6, 7]
Given numList is storing [2, 3, 4, 5, 6, 7] and we are using Python, what does numList look like after inserting number 1 at index 1?
[1, 2, 3, 4, 5, 6, 7]
[2, 1, 3, 4, 5, 6, 7]
[2, 3, 4, 5, 6, 7, 1]
[2, 3, 4, 1, 5, 6, 7]
Given numList is storing [2, 3, 4, 5, 6, 7] and we are using AP CSP Pseudocode, what does numList look like after removing the element at index 2?
[2, 3, 5, 6, 7]
[2, 4, 5, 6, 7]
[2, 3, 4, 6, 7]
[2, 3, 4, 5, 7]
Given numList is storing [2, 3, 4, 5, 6, 7] and we are using Python, what does numList look like after removing the element at index 2?
[2, 3, 5, 6, 7]
[2, 4, 5, 6, 7]
[2, 3, 4, 6, 7]
[2, 3, 4, 5, 7]
What does the `listChecker` procedure do?
It divides each element by 2.
It multiplies each element by 2.
It replaces each element with its index.
It replaces each element with 0 or 1, depending on whether it is even or odd
Given fiboList is assigned [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]. What is the output after the procedure call `listChecker(fiboList)`?
[0, 1, 2, 3, 5, 8, 13, 21, 34, 55]
[1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
[0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1]
What is the final line displayed as a result of the procedure call modifyList(animalList)? Assume AP CSP Pseudocode.
['raccoon', 'turtle', 'duck', 'swan', 'frog', 'beaver', 'lizard', 'deer']
['turtle', 'raccoon', 'swan', 'frog', 'beaver', 'deer', 'lizard']
['turtle', 'duck', 'swan', 'frog', 'beaver', 'deer', 'lizard']
['turtle', 'duck', 'swan', 'frog', 'beaver', 'lizard']
Explain why the binary search is generally more efficient than a linear search.
Binary search checks each element one by one.
Binary search divides the list into halves to find the target.
Binary search only works on unsorted lists.
Binary search is slower than linear search.
Explain when a linear search would be a more appropriate choice for a searching algorithm.
When the list is sorted.
When the list is unsorted.
When the list is very large.
When the list contains only one element.
Consider the following variables: a = 5 b = 7 c = True d = False Evaluate the expression: a < b OR d
True
False
Undefined
None of the above
Consider the following variables: a = 5 b = 7 c = True d = False Evaluate the expression: a != b AND (c OR d)
True
False
Undefined
None of the above
Consider the following variables: a = 5 b = 7 c = True d = False Evaluate the expression: NOT (c OR d) OR NOT (a = b)
True
False
Undefined
None of the above
Consider the following variables: a = 5 b = 7 c = True d = False Evaluate the expression: d AND NOT (a + b = 10)
True
False
Undefined
None of the above
Given a = 1, b = 2, c = False, d = True.
In which problems can you use short circuit evaluation?
a < b OR d
a != b AND (c OR d)
NOT (c OR d) OR NOT (a = b)
c AND NOT (a + b = 4)
Given the following variables in Python: x = 10 y = 2 z = 5 w = 3 What is the result of the expression (x - z) / y?
2.5
1.5
3.0
2.0
Given the following variables in Python: x = 10 y = 2 z = 5 w = 3 What is the result of the expression (x - z) // y?
2.5
1.5
3
2
Given the following variables in Python: a = 5 b = 7 c = 8 d = 10 What is the result of the expression (d * c) % (c - a)?
0
1
2
3
Given the following variables in Python: a = 2 b = 5 c = 7 What is the result of the expression (a**b) + (c**a)?
153
160
24
81
Given the string str_B = "Study Time!", what is the result of the expression str_B[4]?
'T'
' '
'd'
'y'
Given the string str_B = "Study Time!", what is the result of the expression str_B[3:8]?
'y Ti'
'dy Ti'
'y Tim '
'dy Tim'
Given the string str_B = "Study Time!", what is the result of the expression str_B[2:]?
'udy Time!'
'u'
't'
'tudy Time!'
Given the string str_B = "Study Time!", what is the result of the expression str_B[-3]?
'e'
'd'
'm'
Error
Given the string str_B = "Study Time!", what is the result of the expression str_B[-4:]?
'ime!'
'i'
'Time!'
'T'
Is the variable x on line 2 the same variable as x on line 5? Why?
Yes, because they are both named x.
No, because they are in different scopes.
Yes, because they are both integers.
No, because they are in the same scope.
What change could you make to the procedure to make line 2 refer to the global variable x?
Rename the variable x on line 2.
Rename the variable x on line 5.
Insert a line before line 2 that says global x
Use a different function name.
What type of variable would you use if you need to store one of two possible states.
String
Integer
Boolean
Float
When is a compound condition using the logical operator AND true?
When either of the conditions are true
When both conditions are false
When both conditions are true
When exactly one of the conditions is true
Why is a "divide and conquer" search like the binary search more efficient than a linear search?
You only look at half the data set.
You eliminate half the data set with each iteration.
You search all the values.
It divides the data into two sections based on even and odd index values.
What is often used to find a good enough solution when an exact solution is not feasible?
A heuristic approach
An exact algorithm
A brute force method
A polynomial solution
What is the purpose of variables in programming?
They store data values like integers, strings, or booleans
They connect different parts of a program together
They define the precision of floating-point numbers
They serve as pointers to memory addresses
What is an advantage of using functions in a program?
To make the code run faster
To reduce the size of the code
To improve code readability and maintainability
To eliminate the need for variables
What is one way procedures help in achieving abstraction?
By hiding implementation details
By increasing code complexity
By reducing code readability
By making code execution slower
What is one advantage of using simulations in research?
They allow researchers to control and manipulate variables in a safe environment.
They provide real-time feedback from actual events.
They eliminate the need for any real-world testing.
They guarantee accurate predictions of future events.
What is the primary purpose of an API?
To define the structure of a database
To enable communication between different software applications
To provide a user interface for software applications
To compile and execute code
Suppose the pseudocode below started running at 8:00 a.m. on Friday morning and checks every two hours to see if the thermostat needs adjusting. What is the value of the thermostat at 8:00 p.m. Saturday?
64
70
68
Cannot be determined
If statement
DISPLAY(RANDOM(1, 10) < 5)
is executed many times, about what percentage of times does it display true?
40%
44%
50%
100%
Are the two conditional statements equivalent?
Statement 1: x < 100
Statement 2: NOT (x > 100)
Yes
No
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
The equivalent of the above for loop using the while syntax would be
The code above prints all numbers between 1 and 30 that are
not divisible by 5
divisible by 5
How many times will 1 be printed
3
4
5
6
while loop
used to execute a set of statements as long as a condition is true
for loop
used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or string)
break statement
used to stop the loop even if the while condition is true
continue statement
used to stop the current iteration, and continue with the next
