Font size
Worksheets22-23: APCSP Unit 4.4 Variables
Total questions: 8
Worksheet time: 12mins
Nancy is making a program to display a monster on the screen.
This is her code for storing the monster's coordinates:
x ← 55
y ← 82
What will be the value of x after this code runs?
(a)
Devin is making a program to track his grades.
He made the mistake of using the same variable name to track 3 different test grades, though.
Here's a snippet of his code:
a ← 89
a ← 97
a ← 93
What will be the value of a after this code runs?
(a)
Dolores is programming a kitty simulator. Here's part of her code:
hunger ← 6
cuddliness ← 9
playfulness ← 7
DISPLAY (playfulness)
DISPLAY (cuddliness)
DISPLAY (hunger)
After running that code, what will be displayed?
(a)
Frank is making an online ticket buying system for a museum.
His program needs to calculate the final cost of a ticket with extra options added, a planetarium show and an IMAX 3D movie.
The initial code looks like this:
ticket ← 32
starShow ← 16
imax3D ← 9
Which code successfully calculates and stores the final cost?
Note that there may be multiple answers to this question.
finalCost ← ticket + imax3D + starShow
finalCost ← ticket + starShow + imax3D
finalCost ← ticket x starShow x imax3D
finalCost ← ticket % starShow % imax3D
finalCost ← ticket / starShow / imax3D
Nicole read that it's healthy to take 10,000 steps every day.
She's curious how many steps that'd be per minute, walking from 10AM to 10PM, and is writing a program to figure it out.
The program starts with this code:
stepsPerDay ← 10000
hoursAwake ← 12
Which lines of code successfully calculate and store the steps per minute?
Note that there may be multiple answers to this question.
stepsPerMin ← hoursAwake / stepsPerDay / 60
stepsPerMin ← stepsPerDay / hoursAwake % 60
stepsPerMin ← (hoursAwake / stepsPerDay) / 60
stepsPerMin ← (stepsPerDay / hoursAwake) / 60
stepsPerMin ← stepsPerDay / hoursAwake / 60
Google Maps lets users search for anything in the world.
The code to display the map and search results relies on many variables.
Which of these variables are storing a string data type?
Note that there may be multiple answers to this question.
city ← "Beverly Hills"
temp ← 63
weather ← "Partly Cloudy"
longitude ← -118.4008
searchQuery ← "90210"
Carlos 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?
timeLeft: The seconds remaining
playerName: The player's name
score: The number of ghosts captured
soundLevel: The volume of the sound effects ("Boo!")
Amanda is developing a program to track her weekly fitness routine.
Here is a part of her program that sets up some variables:
type ← "swimming"
day ← "wednesday"
duration ← 50
laps ← 20
location ← "YMCA"
How many string variables is this code storing?
(a)
