WorksheetsCSP CodeHS U8 8.2 & 8.2
Total questions: 23
Worksheet time: 46mins
The following code snippet processes a list of strings with a loop and conditionals:
The code relies on one string procedure, LEN(string), which returns the number of characters in the string.
(a)
A movie website lets users create lists of their favorite movies.
When the user first starts, the website runs this code to create an empty list:
favMovies ← []
The user can then insert and remove items from the list.
Here's the code that was executed from one user's session:
"The Lion King", "The Matrix", "Lord of the Rings", "Shrek", "Spider-Man"
"The Lion King", "The Matrix", "Shrek", "Lord of the Rings", "Spider-Man"
"The Lion King", "Toy Story", "Lord of the Rings", "The Matrix", "Shrek", "Spider-Man"
"The Lion King", "Toy Story", "Shrek", "Lord of the Rings", "Spider-Man"
"The Lion King", "Toy Story", "The Matrix", "Lord of the Rings", "Shrek", "Spider-Man"
The following numbers are displayed by a program:
4 8 12 16
The program code is shown below, but it is missing three values: <COUNTER>, <AMOUNT>, and <STEP>.
Given the displayed output, what must the missing values be?
<COUNTER> = 2, <AMOUNT> = 4, <STEP> = 2
<COUNTER> = 1, <AMOUNT> = 4, <STEP> = 2
<COUNTER> = 4, <AMOUNT> = 4, <STEP> = 1
<COUNTER> = 4, <AMOUNT> = 2, <STEP> = 1
<COUNTER> = 2, <AMOUNT> = 2, <STEP> = 1
A program races four avatars against each other: Piceratops, Leafers, Duskpin, and Aqualine.
Here they are lined up at the start line, in that order:
After the first 3 repetitions of each loop, which avatar will be ahead?
Two avatars will be tied for the lead.
A javelin thrower is writing code to track the distance of their throws and how far they are from their target distance.
This is what they have so far:
A friend points out that they can reduce the complexity of their code by using the abstractions of lists and loops.
The programmer decides to "refactor" the code, to rewrite it so that it produces the same output but is structured better.
Which of these is the best refactor of the code?
The two programs below are both intended to display the total number of overtime hours worked, based on a list of logged hours for each day of a week.
Which of these statements best describes these two programs?
Program 1 and Program 2 display the same output and involve the same number of computations.
Program 1 and Program 2 display the same output, but Program 2 requires more computations.
Program 1 and Program 2 display the same output, but Program 1 requires more computations.
Program 1 displays the expected output, while Program 2 displays more output than necessary.
Program 2 displays the expected output, while Program 1 displays more output than necessary.
A vending machine manufacturer is writing code to determine the optimal prices for their products.
The program below processes a list of costs (in dollars and cents). The goal of the program is to create a new list that contains only the costs that can be paid entirely in quarters.
A line of code is missing, however.
What can replace <MISSING CODE> so that this program will work as expected?
APPEND(quarterCosts, costs)
INSERT(quarterCosts, costs)
APPEND(costs, cost)
INSERT(quarterCosts, cost)
APPEND(quarterCosts, cost)
The two procedures below are both intended to return the total number of excess calories eaten in a day based on a list of calories in each meal.
Consider these procedure calls:
excess1 ← calcExcess1([700, 800, 600, 300])
excess2 ← calcExcess2([700, 800, 600, 300])
Which of these statements best describes the difference between the procedure calls?
Both procedure calls return the same value and involve the same number of computations.
Both procedure calls return the same value, but the second procedure requires more computations.
Both procedure calls return the same value, but the first procedure requires more computations.
The first procedure returns the correct value, while the second procedure returns an incorrect value.
The second procedure returns the correct value, while the first procedure returns an incorrect value.
The following code snippet processes a list of strings with a loop and conditional:
The code relies on one string operation, UPPER(string), which returns string in uppercase.
What value will this program display?
(a)
Charlotte is writing code to turn sentences into Pig Latin.
This is what she has so far:
A friend points out that she can reduce the complexity of her code by using the abstractions of lists and loops.
Charlotte decides to "refactor" the code, to rewrite it so that it produces the same output but is structured better.
Which of these is the best refactor of the code?
The code segment below uses a loop to repeatedly operate on a sequence of numbers.
Which description best describes what this program does?
This program multiplies together the integers from 2 to 8 (inclusive).
This program multiplies together the integers from 8 to 15 (inclusive).
This program sums up the integers from 1 to 8 (inclusive).
This program sums up the integers from 8 to 15 (inclusive).
This program sums up the integers from 2 to 8 (inclusive).
KittyBot is a programmable robot that obeys the following commands:
A visual artist is programming a 7x7 LED display:
The code relies on this procedure:
fillPixel(row, column, color) : Lights up the pixel at the given row and column with the given color (specified as a string). The top row is row 1 and the left-most column is column 1.
What will the output of their program look like?
Emmet is creating a program to display words in their binary form, according to the ASCII encoding standard.
This is what his program contains so far:
When this program executes, how many total calls does it make to the DISPLAY procedure?
(a)
Jace is making a simulation of conversations with his 2-year-old son.
Here's the program:
In total, how many times does this code call the yellNo procedure?
(a)
An audio engineer is writing code to display the durations of various songs.
This is what they have so far:
A friend points out that they can reduce the complexity of their code by using the abstractions of lists and loops.
The engineer decides to "refactor" the code, to rewrite it so that it produces the same output but is structured better.
Which of these is the best refactor of the code?
Kobe is working on a basketball game and is experimenting with the variables he'll use for the game. His code looks like this:
1 0 3 3
1 0 3 1
1 0 3 4
1 0 4 3
1 0 1 3
A chemistry student is writing a program to help classify the results of experiments.
Ada notices that her classmate's program is very long and none of the code is grouped into procedures.
How can Ada persuade her classmate to start organizing their code into procedures?
She can find the most slow-running parts of her classmate's program and suggest putting that code into a procedure to make it run faster.
She can find places where her classmate's program has repeated code, and suggest using a procedure to wrap up that code.
She can find buggy parts of her classmate's code and suggest they move those parts into procedures to fix the code.
She can find the most unique part of her classmate's code and suggest they use procedures to hide that functionality from other classmates.
This program uses a conditional to predict the hair type of a baby.
In which situations will hairType be "wavy"?
When fatherAllele is "C" and motherAllele is "C"
When fatherAllele is "s" and motherAllele is "s"
When fatherAllele is "s" and motherAllele is "C"
When fatherAllele is "C" and motherAllele is "s"
The following procedure calculates the slope of a line and takes 4 numeric parameters: the x coordinate of the first point, the y coordinate of the first point, the x coordinate of the second point, and the y coordinate of the second point.
lineSlope(1, 4, 3)
lineSlope(1, 1, 3, 4)
lineSlope(4, 1, 3, 1)
lineSlope(1, 3, 4)
lineSlope(1, 4, 1, 3)
A visual artist is programming an 8x8 LED display:
The code relies on this procedure:
fillPixel(row, column, color) : Lights up the pixel at the given row and column with the given color (specified as a string). The top row is row 0 and the left-most column is column 0.
What will the output of their program look like?
This list represents the horses leading in a race:
What does the leadHorses variable store after that code runs?
"Justify", "Bravazo", "Tenfold", "Good Magic", "Lone Sailor", "Sporting Chance", "Diamond King", "Quip"
"Justify", "Bravazo", "Good Magic", "Lone Sailor", "Tenfold", "Sporting Chance", "Diamond King", "Quip"
"Justify", "Bravazo", "Tenfold", "tempHorse", "Lone Sailor", "Sporting Chance", "Diamond King", "Quip"
"Justify", "Bravazo", "Good Magic", "Lone Sailor", "Sporting Chance", "Diamond King", "Quip"
"Justify", "Bravazo", "Good Magic", "Lone Sailor", "tempHorse", "Sporting Chance", "Diamond King", "Quip"
