wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

22-23: APCSP Unit 4.4 Variables

Total questions: 8

Worksheet time: 12mins

Name
Class
Date
1.

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)  

2.

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)  

3.

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)  

4.

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.

a)

finalCost ← ticket + imax3D + starShow

b)

finalCost ← ticket + starShow + imax3D

c)

finalCost ← ticket x starShow x imax3D

d)

finalCost ← ticket % starShow % imax3D

e)

finalCost ← ticket / starShow / imax3D

5.

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.

a)

stepsPerMin ← hoursAwake / stepsPerDay / 60

b)

stepsPerMin ← stepsPerDay / hoursAwake % 60

c)

stepsPerMin ← (hoursAwake / stepsPerDay) / 60

d)

stepsPerMin ← (stepsPerDay / hoursAwake) / 60

e)

stepsPerMin ← stepsPerDay / hoursAwake / 60

6.

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.

a)

city ← "Beverly Hills"

b)

temp ← 63

c)

weather ← "Partly Cloudy"

d)

longitude ← -118.4008

e)

searchQuery ← "90210"

7.

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?

a)

timeLeft: The seconds remaining

b)

playerName: The player's name

c)

score: The number of ghosts captured

d)

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

8.

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)