wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming AP CS Principles Part 2

Total questions: 15

Worksheet time: 9mins

Name
Class
Date
1.

How could the code be rewritten using the constant and procedures?

There are 2 correct choices.

a)

volume ← (4/3) PI square(radius, 3)

b)

volume ← (4/3) PI square(radius)

c)

volume ← (4/3) PI cube(radius, 3)

d)

volume ← (4/3) PI pow(radius, 3)

e)

volume ← (4/3) PI cube(radius)

2.

In her program, the variable userInput stores the string "Chicken Biggle 007".

Which of the following expressions results in the string "chicken_biggle_007"?

There are 2 correct answers.

a)

REPLACE( LOWER(userInput), " ", "_")

b)

REPLACE( userInput, LOWER(" "), LOWER("_"))

c)

REPLACE( LOWER(userInput), " " → "_" )

d)

REPLACE( LOWER(userInput), "_")

e)

LOWER( REPLACE(userInput, " ", "_"))

3.

How many string variables is this code storing?

(a)  

4.

What will be the value of a after this code runs?

(a)  

5.

The area of the trapezoid is equal to the sum of the length of its bases, multiplied by the half of the height.

Which lines of code successfully calculate the area?

Two answers are correct

a)

area ← (height / 2)(base1 + base2)

b)

area ← height / 2 * base1 + base2

c)

area ← height / 2 * (base1 + base2)

d)

area ← (height / 2) * (base1 + base2)

e)

area ← height / (2 * base1) + base2

6.

After that line of code runs, what will be displayed on the screen?

a)

im mad!!!

b)

IM MAD

c)

IM MAD!!!

d)

im mad

e)

Nothing will be displayed

7.

A toy for a baby indicates that it should only be used for babies that weigh less than 25 pounds and are less than 30 inches tall. The variable weight represents a baby's weight in pounds and the variable height represents a baby's height in inches.

Which of the following expressions evaluates to true if a baby meets the criteria?

a)

NOT (weight ≥ 25) AND NOT (height ≥ 30)

b)

weight > 25 AND height < 30

c)

weight < 25 OR height < 30

d)

NOT (weight ≥ 25) AND height > 30

e)

weight ≤ 25 AND NOT (height < 30)

8.

In total, how many times does this code call the makeLayer procedure?

(a)  

9.

The variable purchaseCost represents a customer's purchase cost and her program needs to set shippingCost to the appropriate value.

Which of these code segments correctly sets the value of shippingCost?

There are 2 correct answers

a)
b)
c)
d)
e)
10.

Which of these tables shows the expected values of chlorineLevel for the given values of chlorinePPM?

a)
b)
c)
d)
11.

Which of these tables shows the expected values of chlorineLevel for the given values of chlorinePPM?

a)

lineSlope(1, 3, 5)

b)

lineSlope(1, 5, 3, 2)

c)

lineSlope(2, 5, 3, 1)

d)

lineSlope(3, 5, 2)

e)

lineSlope(1, 3, 5, 2)

12.

What does the frontRunners variable store after that code runs?

a)

308, 93, 147, 125, 412, 219, 73, 34, 252, 78

b)

308, 147, 93, 412, 219, 73, 34, 252, 78

c)

308, 93, 125, 412, 219, 73, 34, 252, 78

d)

308, 147, 147, 125, 412, 219, 73, 34, 252, 78

e)

308, 147, 93, 93, 412, 219, 73, 34, 252, 78

13.

What does the bestGames variable store after that code runs?

a)

"Dixit", "Codenames", "Carcassonne", "Mysterium", "Scrabble", "Lost Cities"

b)

"Dixit", "Codenames", "Carcassonne", "Mysterium", "Catchphrase", "Lost Cities"

c)

"Dixit", "Carcassonne", "Codenames", "Scrabble", "Catchphrase", "Lost Cities"

d)

"Dixit", "Carcassonne", "Codenames", "Mysterium", "Catchphrase", "Lost Cities"

e)

"Dixit", "Carcassonne", "Mysterium", "Catchphrase", "Lost Cities"

14.

After running that code, what does the sevenWonders list store?

a)

"Aurora", "Grand Canyon", "Great Barrier Reef", "Komodo", "Mount Everest", "Table Mountain", "Victoria Falls"

b)

"Aurora", "Grand Canyon", "Great Barrier Reef", "Guanabara Bay", "Komodo", "Parícutin", "Table Mountain"

c)

"Aurora", "Grand Canyon", "Great Barrier Reef", "Guanabara Bay", "Komodo", "Table Mountain", "Victoria Falls"

d)

"Aurora", "Grand Canyon", "Great Barrier Reef", "Guanabara Bay", "Komodo", "Mount Everest", "Table Mountain", "Parícutin", "Victoria Falls"

e)

"Aurora", "Grand Canyon", "Great Barrier Reef", "Guanabara Bay", "Mount Everest", "Komodo", "Parícutin", "Table Mountain", "Victoria Falls"

15.

What does this program output to the display?

a)

bird.avi dog.wav

b)

cat.jpg cow.mov

c)

bird.avi bird.avi

d)

bird.avi cat.jpg

e)

cat.jpg dog.wav