wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP CSP Midterm Exam Review

Total questions: 50

Worksheet time: 26mins

Name
Class
Date
1.

What terminates this iteration?

a)

When i equals j.

b)

When userMax equals i.

c)

When userMax is less than 0.

d)

When userMax is greater than 10.

2.

When does the Boolean in the if-else statement evaluate to false?

a)

When userMax is greater than 0.

b)

When userMax is less than 0.

c)

When userMax is equal to 0.

d)

When userMax is less than 1.

3.

What is the point of calling the userInputSeq procedure inside the if-statement’s block of code?

a)

To reset the userMax variable.

b)

To display the sum of the numbers.

c)

To prompt the user to enter a valid number.

d)

To terminate the loop.

4.

What role does the variable `n` play in the procedure? How would the code be different if there wasn’t a parameter?

a)

`n` determines the number of times the message is displayed; without `n`, the message would display once.

b)

`n` determines the message content; without `n`, the message would be empty.

c)

`n` determines the display order; without `n`, the order would be reversed.

d)

`n` determines the display speed; without `n`, the message would display slowly.

5.

Which statement is NOT true?

a)

2 MOD 4 = 0

b)

15 MOD 2 = 1

c)

17 MOD 3 = 2

d)

25 MOD 4 = 1

6.

Given the procedure call `getAnyNumber(5, 20)`, what is the maximum possible value for `getNum`?

a)

5

b)

15

c)

19

d)

20

7.

Explain the functionality check of the if-else control structure in version B of getAnyNumber:

a)

It only generates a random number when num1 and num2 are equal

b)

It only generates a random number when num1 and num2 are not equal

8.

What is displayed after the procedure call list1(numList)?

a)

[2, 3, 4, 5, 6, 7]

b)

[20, 30, 40, 50, 60, 70]

c)

[2, 30, 4, 50, 6, 70]

d)

[20, 3, 40, 5, 60, 7]

9.

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?

a)

[1, 2, 3, 4, 5, 6, 7]

b)

[2, 1, 3, 4, 5, 6, 7]

c)

[2, 3, 4, 5, 6, 7, 1]

d)

[2, 3, 4, 1, 5, 6, 7]

10.

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?

a)

[1, 2, 3, 4, 5, 6, 7]

b)

[2, 1, 3, 4, 5, 6, 7]

c)

[2, 3, 4, 5, 6, 7, 1]

d)

[2, 3, 4, 1, 5, 6, 7]

11.

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?

a)

[2, 3, 5, 6, 7]

b)

[2, 4, 5, 6, 7]

c)

[2, 3, 4, 6, 7]

d)

[2, 3, 4, 5, 7]

12.

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?

a)

[2, 3, 5, 6, 7]

b)

[2, 4, 5, 6, 7]

c)

[2, 3, 4, 6, 7]

d)

[2, 3, 4, 5, 7]

13.

What does the `listChecker` procedure do?

a)

It divides each element by 2.

b)

It multiplies each element by 2.

c)

It replaces each element with its index.

d)

It replaces each element with 0 or 1, depending on whether it is even or odd

14.

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)`?

a)

[0, 1, 2, 3, 5, 8, 13, 21, 34, 55]

b)

[1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]

c)

[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]

d)

[0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1]

15.

What is the final line displayed as a result of the procedure call modifyList(animalList)? Assume AP CSP Pseudocode.

a)

['raccoon', 'turtle', 'duck', 'swan', 'frog', 'beaver', 'lizard', 'deer']

b)

['turtle', 'raccoon', 'swan', 'frog', 'beaver', 'deer', 'lizard']

c)

['turtle', 'duck', 'swan', 'frog', 'beaver', 'deer', 'lizard']

d)

['turtle', 'duck', 'swan', 'frog', 'beaver', 'lizard']

16.

Explain why the binary search is generally more efficient than a linear search.

a)

Binary search checks each element one by one.

b)

Binary search divides the list into halves to find the target.

c)

Binary search only works on unsorted lists.

d)

Binary search is slower than linear search.

17.

Explain when a linear search would be a more appropriate choice for a searching algorithm.

a)

When the list is sorted.

b)

When the list is unsorted.

c)

When the list is very large.

d)

When the list contains only one element.

18.

Consider the following variables: a = 5 b = 7 c = True d = False Evaluate the expression: a < b OR d

a)

True

b)

False

c)

Undefined

d)

None of the above

19.

Consider the following variables: a = 5 b = 7 c = True d = False Evaluate the expression: a != b AND (c OR d)

a)

True

b)

False

c)

Undefined

d)

None of the above

20.

Consider the following variables: a = 5 b = 7 c = True d = False Evaluate the expression: NOT (c OR d) OR NOT (a = b)

a)

True

b)

False

c)

Undefined

d)

None of the above

21.

Consider the following variables: a = 5 b = 7 c = True d = False Evaluate the expression: d AND NOT (a + b = 10)

a)

True

b)

False

c)

Undefined

d)

None of the above

22.

Given a = 1, b = 2, c = False, d = True.

In which problems can you use short circuit evaluation?

a)

a < b OR d

b)

a != b AND (c OR d)

c)

NOT (c OR d) OR NOT (a = b)

d)

c AND NOT (a + b = 4)

23.

Given the following variables in Python: x = 10 y = 2 z = 5 w = 3 What is the result of the expression (x - z) / y?

a)

2.5

b)

1.5

c)

3.0

d)

2.0

24.

Given the following variables in Python: x = 10 y = 2 z = 5 w = 3 What is the result of the expression (x - z) // y?

a)

2.5

b)

1.5

c)

3

d)

2

25.

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)?

a)

0

b)

1

c)

2

d)

3

26.

Given the following variables in Python: a = 2 b = 5 c = 7 What is the result of the expression (a**b) + (c**a)?

a)

153

b)

160

c)

24

d)

81

27.

Given the string str_B = "Study Time!", what is the result of the expression str_B[4]?

a)

'T'

b)

' '

c)

'd'

d)

'y'

28.

Given the string str_B = "Study Time!", what is the result of the expression str_B[3:8]?

a)

'y Ti'

b)

'dy Ti'

c)

'y Tim '

d)

'dy Tim'

29.

Given the string str_B = "Study Time!", what is the result of the expression str_B[2:]?

a)

'udy Time!'

b)

'u'

c)

't'

d)

'tudy Time!'

30.

Given the string str_B = "Study Time!", what is the result of the expression str_B[-3]?

a)

'e'

b)

'd'

c)

'm'

d)

Error

31.

Given the string str_B = "Study Time!", what is the result of the expression str_B[-4:]?

a)

'ime!'

b)

'i'

c)

'Time!'

d)

'T'

32.

Is the variable x on line 2 the same variable as x on line 5? Why?

a)

Yes, because they are both named x.

b)

No, because they are in different scopes.

c)

Yes, because they are both integers.

d)

No, because they are in the same scope.

33.

What change could you make to the procedure to make line 2 refer to the global variable x?

a)

Rename the variable x on line 2.

b)

Rename the variable x on line 5.

c)

Insert a line before line 2 that says global x

d)

Use a different function name.

34.

What type of variable would you use if you need to store one of two possible states.

a)

String

b)

Integer

c)

Boolean

d)

Float

35.

When is a compound condition using the logical operator AND true?

a)

When either of the conditions are true

b)

When both conditions are false

c)

When both conditions are true

d)

When exactly one of the conditions is true

36.

Why is a "divide and conquer" search like the binary search more efficient than a linear search?

a)

You only look at half the data set.

b)

You eliminate half the data set with each iteration.

c)

You search all the values.

d)

It divides the data into two sections based on even and odd index values.

37.

What is often used to find a good enough solution when an exact solution is not feasible?

a)

A heuristic approach

b)

An exact algorithm

c)

A brute force method

d)

A polynomial solution

38.

What is the purpose of variables in programming?

a)

They store data values like integers, strings, or booleans

b)

They connect different parts of a program together

c)

They define the precision of floating-point numbers

d)

They serve as pointers to memory addresses

39.

What is an advantage of using functions in a program?

a)

To make the code run faster

b)

To reduce the size of the code

c)

To improve code readability and maintainability

d)

To eliminate the need for variables

40.

What is one way procedures help in achieving abstraction?

a)

By hiding implementation details

b)

By increasing code complexity

c)

By reducing code readability

d)

By making code execution slower

41.

What is one advantage of using simulations in research?

a)

They allow researchers to control and manipulate variables in a safe environment.

b)

They provide real-time feedback from actual events.

c)

They eliminate the need for any real-world testing.

d)

They guarantee accurate predictions of future events.

42.

What is the primary purpose of an API?

a)

To define the structure of a database

b)

To enable communication between different software applications

c)

To provide a user interface for software applications

d)

To compile and execute code

43.

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?

a)

64

b)

70

c)

68

d)

Cannot be determined

44.

If statement

DISPLAY(RANDOM(1, 10) < 5)

is executed many times, about what percentage of times does it display true?

a)

40%

b)

44%

c)

50%

d)

100%

45.

Are the two conditional statements equivalent?

Statement 1: x < 100

Statement 2: NOT (x > 100)

a)

Yes

b)

No

46.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

47.

The equivalent of the above for loop using the while syntax would be

a)
b)
c)
d)
48.

The code above prints all numbers between 1 and 30 that are

a)

not divisible by 5

b)

divisible by 5

49.

How many times will 1 be printed

a)

3

b)

4

c)

5

d)

6

50.

Match the following

a)

while loop

1.

used to execute a set of statements as long as a condition is true

b)

for loop

2.

used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or string)

c)

break statement

3.

used to stop the loop even if the while condition is true

d)

continue statement

4.

used to stop the current iteration, and continue with the next