WorksheetsAP CSP Unit 3 Quiz 2
Total questions: 15
Worksheet time: 14mins
DISPLAY (">")
DISPLAY ("_")
DISPLAY ("<")
>_<
> _ <
<_>
< _ >
<
_
>
Viktoria is writing a program to communicate with pirates:
DISPLAY ("Ahoy")
DISPLAY ("mateys!")
This is a computer program with (a) statements.
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)
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?
carton ← 12 -(neededEggs MOD 12)
carton ← (neededEggs + (12 - (neededEggs MOD 12)))/12
carton ← (12 - (neededEggs / 12))/12
carton ← (neededEggs MOD 12) - 12
x = 5
y = 6
print(x*y)
Select all the correct answer(s):
x is a variable
x is a value
print() is a funciton
30 will be shown in the console.
print(x*y) is an assignment statement
In Python, what is the final result of the expression 6 / 2 + 6 ?
(a)
What does the following program print?
a = "hi"
b = 4
c = a * b
print(type(c))
<type 'str'>
<type 'int'>
<type 'float'>
The program crashes and doesn’t print anything.
Given the following code:
x = "10"
y = "20"
print(x + y)
What will be shown in the console?
(a)
Given the following code:
x = "10"
y = "20"
print(int(x) + int(y))
What will be shown in the console?
(a)
A memory space where you store values
a data type for saving data
a type of memory to calculate formulas
x = 5
y = 6
print("x*y")
The code above displays the following:
11
x*y
Syntax Error
30
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?
soundLevel: The volume of the sound effects ("Boo!")
score: The number of ghosts captured
timeLeft: The seconds remaining
playerName: The player's name
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"?
name ← concatenate(concatenate(first2, " "), mid2)
name ← concatenate(first2, " ", mid2)
name ← concatenate(first2, concatenate(" "), mid2)
name ← concatenate(first2 + " " + mid2)
name ← concatenate(first2, " ", concatenate(mid2))
Harper is writing code to calculate the surface area of a sphere, based on this formula:
Surface area = 4πr2
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)
surfaceArea ← 4 * PI *(radius * radius)
surfaceArea ← 4 * PI * square(radius)
surfaceArea ← 4* PI * cube(radius, 2)
surfaceArea ← 4* PI * pow(radius)
surfaceArea ← 4* PI * pow(radius, 2)
