CodeHS - AP CSP - Python Midterm (Units 3-7) Easy

 

AP CSP Units 3–7 Programming Review Quiz

40 Multiple-Choice Questions

 

 

Unit 3: Variables, Input, Output

1. What will the following code print? x = 4
y = x + 3
print(y)
A. 4
B. 3
C. 7
D. Error
2. Which of the following is a valid variable name?
A. 3value
B. value_3
C. value-3
D. value 3
3. What is x after the code runs? x = 10
x = x - 3
x = x * 2
A. 7
B. 14
C. 20
D. 24
4. Which expression evaluates to a Boolean?
A. x + 7
B. "hello"
C. x > 10
D. print(x)
5. What is printed? name = "Alex"
print("Hi " + name)
A. Hi
B. Alex
C. Hi Alex
D. Error
6. If the user enters 5, what is printed? num = int(input())
print(num * 3)
A. 3
B. 5
C. 8
D. 15
7. Which operator means "remainder"?
A. //
B. /
C. %
D. **
8. Assignment operator (=) does what?
A. Checks equality
B. Stores a value
C. Repeats code
D. Creates a Boolean

 

 

 

Unit 4: Conditionals & Boolean Logic

9. What is printed? x = 8
if x > 10:
  print("big")
else:
  print("small")
A. big
B. small
C. Error
D. Nothing
10. True only when BOTH a and b are True:
A. a or b
B. a == b
C. a and b
D. not a or b
11. What is printed? x = 4
if x == 4:
  print("A")
elif x > 4:
  print("B")
else:
  print("C")
A. A
B. B
C. C
D. Nothing
12. Equivalent to not (A or B):
A. (not A) or (not B)
B. (not A) and (not B)
C. A and B
D. A != B
13. What is printed? temp = 95
if temp > 100 or temp < 32:
  print("Extreme")
else:
  print("Normal")
A. Extreme
B. Normal
C. temp
D. Error
14. True only when exactly one is True:
A. A and B
B. A != B
C. A == B
D. not A and not B
15. What is printed? x = 10
y = 3
if x % y == 1:
  print("yes")
else:
  print("no")
A. yes
B. no
C. 1
D. Error
16. What does this check? if age >= 13 and age <= 18: A. age is 13
B. age is 13–18 inclusive
C. age is NOT between 13–18
D. age > 18

 

 

Unit 5: Loops (For & While)

17. How many times does this loop run? for i in range(5): print(i) A. 4
B. 5
C. 6
D. Infinite
18. What is printed? i = 1
while i < 4:
  print(i)
  i += 1
A. 1
B. 1 2
C. 1 2 3
D. 2 3 4
19. What is printed? for i in range(2, 10, 2): print(i) A. 2 4 6 8
B. 2 3 4 5
C. 2 4 6 8 10
D. Error
20. What does this loop do? count = 0
while count < 3:
  count += 1
A. Prints numbers
B. Runs 3 times
C. Infinite loop
D. Error
21. What is printed? sum = 0
for n in [3,6,9]:
  sum += n
print(sum)
A. 9
B. 18
C. 12
D. 24
22. Output? for c in "CSP":
  print(c.lower())
A. CSP
B. csp
C. C S P
D. c
  s
  p
23. What is printed? x = 5
while x > 0:
  x -= 2
print(x)
A. 5
B. 3
C. 1
D. -1
24. Which runs exactly 10 iterations?
A. for i in range(10)
B. for i in range(1,10)
C. while i < 10
D. for i in range(5,15)
25. What does break do?
A. Skip iteration
B. Stop loop
C. Restart loop
D. Ignore errors
26. What does continue do?
A. Skip to next iteration
B. End loop
C. Pause
D. Restart

 

 

Unit 6: Lists & Strings

27. What is printed? nums = [10,20,30]
print(nums[1])
A. 10
B. 20
C. 30
D. Error
28. What is printed? lst = [2,4,6,8]
print(len(lst))
A. 3
B. 4
C. 5
D. Error
29. append() does what?
A. Add to front
B. Add to end
C. Remove last
D. Clear list
30. What is printed? nums = [5,3,9]
for n in nums:
  print(n*2)
A. 5 3 9
B. 10 6 18
C. 5
D. 3
31. What is printed? nums = [1,2,3,4]
print(nums[1:3])
A. [1,2]
B. [2,3]
C. [2,3,4]
D. [3,4]
32. What is printed? s = "hello"
print(s[1])
A. h
B. e
C. l
D. o
33. What is printed? pets = ["cat","dog","bird"]
pets[1] = "hamster"
print(pets)
A. ["cat","hamster","bird"]
B. ["cat","dog","bird"]
C. ["hamster","dog","bird"]
D. Error
34. Method that counts substring occurrences?
A. len()
B. count()
C. find()
D. sum()

 

 

Unit 7: Functions

35. What does this function print? def greet():
  print("Hi")
greet()
A. Hi
B. greet
C. Nothing
D. Error
36. What is printed? def add(a,b):
  return a+b
print(add(3,4))
A. 3
B. 4
C. 7
D. 12
37. Which keyword returns a value?
A. give
B. return
C. stop
D. send
38. What is printed? def f(x):
  return x*2
print(f(5))
A. 5
B. 2
C. 7
D. 10
39. What is printed? def area(w,h):
  return w*h
print(area(3,4))
A. 7
B. 12
C. 34
D. Error
40. Parameters allow functions to:
A. Be integers only
B. Receive input
C. Never change
D. Be optional only

 

 

Answer Key & Explanations

1. C – 4 + 3 = 7.
2. B – variable names cannot start with numbers or contain spaces/hyphens.
3. C – (10 – 3) × 2 = 14 → 20.
4. C – Comparisons produce Booleans.
5. C – String concatenation.
6. D – 5 × 3 = 15.
7. C – % is remainder.
8. B – Assignment stores values.
9. B – 8 is not > 10.
10. C – AND requires both true.
11. A – First condition is true.
12. B – De Morgan’s Law.
13. B – 95 is normal range.
14. B – XOR condition.
15. B – 10 % 3 = 1 → condition false.
16. B – Inclusive range.
17. B – range(5) → 0–4.
18. C – Prints 1, 2, 3.
19. A – Even numbers 2–8.
20. B – Loop runs 3 times.
21. B – 3 + 6 + 9 = 18.
22. D – Each letter printed on its own line.
23. D – 5→3→1→-1.
24. D – 5–14 = 10 iterations.
25. B – break stops loop entirely.
26. A – continue skips to next iteration.
27. B – Index 1 = 20.
28. B – Four elements.
29. B – Append adds to end.
30. B – Doubles each number.
31. B – Slice 1–2.
32. B – s[1] = e.
33. A – Replaces middle element.
34. B – count() counts occurrences.
35. A – Prints Hi.
36. C – 3+4 = 7.
37. B – return keyword.
38. D – 5*2 = 10.
39. B – 3×4 = 12.
40. B – Parameters → input.

Contact form