Mr.Mou @ ShiShi AP Center

AP CSP

CSP Exam 2023:



Core Concepts:
核心知识点


2023 AP Exam On-Demand Review


CB官方样题

Assume that the list originalList contains integer values and that the list newList is initially empty. The following code segment is intended to copy all even numbers from originalList to newList so that the numbers in newList appear in the same relative order as in originalList. The code segment may or may not work as intended.

Line 1: FOR EACH number IN originalList
Line 2: {
Line 3:   IF (number MOD 2 = 0)
Line 4:   {
Line 5:       INSERT (newList, 1, number)
Line 6:   }
Line 7: }

Which of the following changes, if any, can be made so that the code segment works as intended?
(A) Changing line 1 to FOR EACH number IN newList
(B) Changing line 3 to IF (number MOD 2 = 1)
(C) Changing line 5 to APPEND (newList, number)
(D) No change is needed; the code segment is correct as is.


computer science principles course topics

Screen Shot 2023-03-31 at 12 34 52 PM-min