CodeHS - AP CSP - Python Midterm (Units 3-7) Medium Difficulty

 

AP CSP Units 3–7 Medium Difficulty Quiz

Auto-Graded • 40 Questions

Unit 3: Variables, Expressions, Tracing

1. What is printed? x = 3 y = x * 2 x = y - 1 print(x + y) A. 7
B. 8
C. 9
D. 11
2. What is the value of result? a = 4 b = 7 result = (a + b) // 3 + b % a A. 2
B. 3
C. 4
D. 6
3. Which evaluates to True?
A. "5" + 2 == 7
B. 5 > 3 and not (2 > 3)
C. 5 == "5"
D. not(5 > 2 or 1 < 3)
4. What does the following print? x = 12 print(x % 5 + x // 4) A. 3
B. 4
C. 5
D. 6
5. Which expression is equivalent to: “x is NOT between 10 and 20 inclusive”? A. not (10 <= x <= 20)
B. x < 10 and x > 20
C. x < 10 or x > 20
D. x <= 10 or x >= 20

Unit 4: Conditionals

6. What is printed? x = 5 if x % 2 == 1: if x > 3: print("A") else: print("B") else: print("C") A. A
B. B
C. C
D. Nothing
7. Which Boolean is True only when x and y are different?
A. x == y
B. x != y
C. x and y
D. not x and not y
8. What is printed? a = 10 b = 4 if a / b > 2: print("high") else: print("low") A. high
B. low
C. Error
D. Nothing
9. What is printed? x = 8 y = 3 if x % y == 2: print("A") elif x % y == 1: print("B") else: print("C") A. A
B. B
C. C
D. Nothing
10. Which is equivalent to NOT (A and B)? A. (not A) or (not B)
B. (not A) and (not B)
C. A or B
D. A != B

Unit 5: Loops

11. What is printed? sum = 0 for i in range(1, 6): sum += i print(sum) A. 10
B. 12
C. 15
D. 21
12. How many times does this loop run? count = 10 while count > 3: count -= 3 A. 1
B. 2
C. 3
D. 4
13. What is printed? for i in range(3): for j in range(2): print(i + j) A. 0 1 1 2 2 3
B. 0 1 2 3 4 5
C. 0 1 2 2 3 4
D. 0 1 1 2 2 3
14. What is printed? x = 7 while x % 3 != 0: x += 2 print(x) A. 7
B. 9
C. 11
D. 13
15. What is printed? total = 1 for i in [2,3,4]: total *= i print(total) A. 18
B. 20
C. 24
D. 32
16. What happens? i = 0 while i < 5: print(i) A. Prints 0–4
B. Prints nothing
C. Infinite loop
D. Error
17. What is printed? for i in range(1,10,3): print(i) A. 1 3 5 7 9
B. 1 4 7
C. 1 4 7 10
D. 3 6 9
18. What is printed? x = 20 while x >= 10: x -= 4 print(x) A. 8
B. 4
C. 0
D. -4

Unit 6: Lists and Strings

19. What is printed? nums = [2, 5, 8, 11, 14] print(nums[nums[1]]) A. 2
B. 5
C. 8
D. 14
20. What is the list after execution? a = [1,2,3,4] b = a b[2] = 99 A. [1,2,3,4]
B. [1,2,99,4]
C. [1,99,3,4]
D. Error
21. What is printed? lst = [10,20,30,40] print(lst[-2]) A. 10
B. 20
C. 30
D. 40
22. What is printed? items = ["a","b","c","d","e"] print(items[1:4:2]) A. ['b','c']
B. ['b','d']
C. ['a','c']
D. ['c','e']
23. What is printed? s = "CSPROCKS" print(s[2:6]) A. CSPRO
B. PROCK
C. PROC
D. SROC
24. What is printed? pets = ["cat","dog","bird","fish"] print(len(pets) - pets.index("bird")) A. 1
B. 2
C. 3
D. 4
25. Which list contains only elements at even indexes? data = [10,20,30,40,50] A. data[1::2]
B. data[2::2]
C. data[::2]
D. data[::-1]
26. What is printed? lst = [3,6,9] for i in range(len(lst)): lst[i] += i print(lst) A. [3,6,9]
B. [3,7,11]
C. [3,6,12]
D. [4,7,10]

Unit 7: Functions

27. What is printed? def f(x): return x + 2 print(f(f(3))) A. 5
B. 6
C. 7
D. 8
28. What is printed? def mystery(a,b): if a > b: return a - b return b - a print(mystery(8,3)) A. 3
B. 5
C. 8
D. 11
29. What is printed? def foo(n): if n % 2 == 0: return n // 2 return n * 3 print(foo(foo(4))) A. 1
B. 2
C. 3
D. 6
30. What is printed? def g(x,y): return x*y - x print(g(3,4)) A. 6
B. 9
C. 12
D. 15
31. What is printed? def h(a): return a + 1 def k(a): return h(a) * 2 print(k(3)) A. 4
B. 6
C. 8
D. 10
32. What is printed? def f(x): x += 1 return x a = 5 f(a) print(a) A. 5
B. 6
C. 7
D. Error
33. What is printed? def m(x): return x * x print(m(m(2))) A. 2
B. 4
C. 16
D. 256
34. What is printed? def combine(a,b): return str(a) + str(b) print(combine(3, combine(1,2))) A. 312
B. 3212
C. 31212
D. 312
35. What is printed? def calc(a,b,c): return a + b * c print(calc(2,3,4)) A. 14
B. 20
C. 24
D. 9
36. What is printed? def fun(n): return n % 4 print(fun(fun(fun(10)))) A. 0
B. 1
C. 2
D. 3
37. What is returned? def foo(a,b): if a > b: return True return False print(foo(5,1)) A. True
B. False
C. 1
D. Error
38. What is printed? def p(x): return x - 1 def q(x): return p(x) * 2 print(q(6)) A. 5
B. 10
C. 12
D. 14
39. What is printed? def f(n): if n == 0: return 1 return n + f(n-1) print(f(3)) A. 3
B. 4
C. 6
D. 7
40. What is printed? def r(a,b): return (a + b) // 2 print(r(7,4)) A. 4
B. 5
C. 6
D. 7

 

Contact form