wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP Computer Science Principles Unit 5 Review Lists

Total questions: 24

Worksheet time: 1hrs 2mins

Name
Class
Date
1.

Which vocabulary word is:

a common method for referencing the elements in a list or string using numbers

a)

list

b)

element

c)

index

2.

Which vocabulary word is:

an ordered collection of elements

a)

list

b)

element

c)

index

3.

Which vocabulary word is:

an individual value in a list that is assigned a unique index

a)

list

b)

element

c)

index

4.

What is the value of i after this code runs?


var myNumbers = [32, 64, 33, 0, 15, 26, 3];

var i = myNumbers[4];

a)

64

b)

15

c)

0

d)

32

5.

//Consider this code:

var list = [10, 12, 14, 16, 18];

appendItem(list, 3);

insertItem(list, 2, 20);

removeItem(list, 0);


//What is printed to the console?

console.log(list);

a)

10, 12, 14, 16, 18

b)

10, 12, 14 , 20, 16, 18, 3

c)

3, 12, 14, 20, 16, 18

d)

12, 20, 14, 16, 18, 3

6.

//Consider this code:

var list = [10, 12, 14, 16, 18];

appendItem(list, 3);

insertItem(list, 2, 20);

removeItem(list, 0);


//What is printed to the console?

console.log(list[0]);

(a)  

7.

//Consider this code:

var list = [10, 12, 14, 16, 18];

appendItem(list, 3);

insertItem(list, 2, 20);

removeItem(list, 0);


//What is printed to the console?

console.log(list.length);

(a)  

8.

//Consider this code:

var list = [10, 12, 14, 16, 18];

appendItem(list, 3);

insertItem(list, 2, 20);

removeItem(list, 0);


//What is printed to the console?

console.log(list[list.length-1]);

(a)  

9.

//Consider this code.


var beginning = "My name is ";

var end = "Mrs. Anderson";

var sentence = beginning + end;


//What is printed to the console?

console.log(sentence.length);

a)

name

b)

name is

c)

y name

d)

23

e)

n

10.

//Consider this code.


var beginning = "My name is ";

var end = "Mrs. Anderson";

var sentence = beginning + end;


//What is printed to the console?

console.log(sentence.substring(2, 7);

a)

_name

b)

name_is

c)

y_name

d)

23

e)

n

11.

//Consider this code.


var beginning = "My name is ";

var end = "Mrs. Anderson";

var sentence = beginning + end;


//What is printed to the console?

console.log(sentence.substring(1, 6);

a)

_name

b)

name_is

c)

y_nam

d)

23

e)

n

12.

//Consider this code.


var beginning = "My name is ";

var end = "Mrs. Anderson";

var sentence = beginning + end;


//What is printed to the console?

console.log(sentence.substring(3, 10);

a)

_name

b)

name_is

c)

y_name

d)

23

e)

n

13.
a)

1

b)

2

c)

3

d)

6

e)

Error. There is no index 2.

14.
a)
b)
c)
d)
e)
15.
a)

0

b)

1

c)

2

d)

8

e)

Error. Index 3 does not exist.

16.
a)
b)
c)
d)
e)
17.
a)

2

b)

3

c)

4

d)

5

e)

6

18.
a)

4

b)

7

c)

9

d)

10

e)

ab

19.
a)
b)
c)
d)
e)
20.

A Boolean expression is an expression that evaluates to which of the of the following?

a)

Yes/Maybe/No

b)

True/False

c)

Any Integer

d)

Integers between 1 and 10

e)

Any single character

21.

What is a possible output when the following code segment executes? The ending position of the turtle is shown in each diagram. The starting position is shown as a white triangle in cases where the turtle starts and ends in different locations.

a)
b)
c)
d)
e)
22.
a)
b)
c)
d)
e)
23.

A list of numbers has n elements, indexed from 1 to n. The following algorithm is intended to display the number of elements in the list that have a value greater than 100. The algorithm uses the variables count and position. Steps 3 and 4 are missing.

Step 1: Set count to 0 and position to 1.

Step 2: If the value of the element at index position is greater than 100, increase the value of count by 1.

Step 3: (missing step)

Step 4: (missing step)

Step 5: Display the value of count.

Which of the following could be used to replace steps 3 and 4 so that the algorithm works as intended?

a)

Step 3: Increase the value of position by 1.

Step 4: Repeat steps 2 and 3 until the value of count is greater than 100.

b)

Step 3: Increase the value of position by 1.

Step 4: Repeat steps 2 and 3 until the value of position is greater than n.

c)

Step 3: Repeat step 2 until the value of count is greater than 100.

Step 4: Increase the value of position by 1.

d)

Step 3: Repeat step 2 until the value of position is greater than n.

Step 4: Increase the value of count by 1.

24.

Which of the following code segments can be used to move the robot to the gray square?

Select two answers.

a)
b)
c)
d)