Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP CSP Unit 3 Quiz 2

Total questions: 15

Worksheet time: 14mins

Name
Class
Date
1.

DISPLAY (">")

DISPLAY ("_")

DISPLAY ("<")

a)

>_<

b)

> _ <

c)

<_>

d)

< _ >

e)

<

_

>

2.

Viktoria is writing a program to communicate with pirates:

DISPLAY ("Ahoy")

DISPLAY ("mateys!")

This is a computer program with (a)   statements.

3.

Mr. Todd's class is going on a field trip to the CS History Museum. They need to take shuttles there, so he's writing a program to calculate how many shuttles they'll need to take.

Here's his code for initializing the variables:

numStudents ← 33

numSeats ← 12

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

(a)  

4.

Melody is organizing a bake sale and making a program to help her plan the ingredients.

Each batch of cookies requires 4 eggs, and she's going to make 5 batches.

This code calculates the total eggs required:

eggsInBatch ← 4

numBatches ← 5

neededEggs ← eggsInBatch * numBatches

Melody realizes she'll need to buy more eggs than necessary, since she needs to buy eggs by the dozen.

Now she wants to calculate how many eggs will be leftover in the final carton of eggs. That will help her decide whether to make extra icing.

Which line of code can calculate how many cartons is needed?

a)

carton ← 12 -(neededEggs MOD 12)

b)

carton ← (neededEggs + (12 - (neededEggs MOD 12)))/12

c)

carton ← (12 - (neededEggs / 12))/12

d)

carton ← (neededEggs MOD 12) - 12

5.
Converts a number to a string
a)
str()
b)
int()
c)
parseInt()
d)
convert
6.

x = 5

y = 6

print(x*y)

Select all the correct answer(s):

a)

x is a variable

b)

x is a value

c)

print() is a funciton

d)

30 will be shown in the console.

e)

print(x*y) is an assignment statement

7.

In Python, what is the final result of the expression 6 / 2 + 6 ?

(a)  

8.

What does the following program print?

a = "hi"

b = 4

c = a * b


print(type(c))

a)

<type 'str'>

b)

<type 'int'>

c)

<type 'float'>

d)

The program crashes and doesn’t print anything.

9.

Given the following code:
x = "10"

y = "20"

print(x + y)
What will be shown in the console?

(a)  

10.

Given the following code:
x = "10"

y = "20"

print(int(x) + int(y))
What will be shown in the console?

(a)  

11.
What is a variable?
a)

A memory space where you store values

b)
a type of graphics
c)

a data type for saving data

d)

a type of memory to calculate formulas

12.

x = 5

y = 6

print("x*y")


The code above displays the following:

a)

11

b)

x*y

c)

Syntax Error

d)

30

13.

Casper is programming a game called GhostHunter Extreme, where players must capture as many ghosts as possible in 5 minutes.

Which variable would he most likely use a string data type for?

a)

soundLevel: The volume of the sound effects ("Boo!")

b)

score: The number of ghosts captured

c)

timeLeft: The seconds remaining

d)

playerName: The player's name

14.

Kunto is working on a program for generating baby name ideas.

Her program uses the procedure (see image) for string concatenation.

These variables are at the start of her program:

first1 ← "Ella"

first2 ← "Kai"

mid1 ← "Mae"

mid2 ← "Lynn"

Which line of code would store the string "Kai Lynn"?

a)

name ← concatenate(concatenate(first2, " "), mid2)

b)

name ← concatenate(first2, " ", mid2)

c)

name ← concatenate(first2, concatenate(" "), mid2)

d)

name ← concatenate(first2 + " " + mid2)

e)

name ← concatenate(first2, " ", concatenate(mid2))

15.

Harper is writing code to calculate the surface area of a sphere, based on this formula:

Surface area = 4πr24\pi r^2

They then discover that the coding environment has a built-in constant for PI plus a number of useful mathematical procedures in the image.

How could the code be rewritten using the constant and procedures? (Select all that apply)

a)

surfaceArea ← 4 * PI *(radius * radius)

b)

surfaceArea ← 4 * PI * square(radius)

c)

surfaceArea ← 4* PI * cube(radius, 2)

d)

surfaceArea ← 4* PI * pow(radius)

e)

surfaceArea ← 4* PI * pow(radius, 2)