Remember: To read code, go line by line, use the names as clues, run it by hand with small numbers, and check comments against the code.
Read and answer
Read the story, then answer.
A wall of linesMina opens Teo's Dance Party code, and a wall of lines fills the screen. Mr. Reyes says to read it like a recipe, one line at a time. She hunts for names, because a name in code is a clue, and she spots beat count, dance speed and moves. She finds a loop that repeats the dance, adding one to beat count each time, and she runs it on paper with small numbers: beat count starts at zero and goes up one, two, three, four, five. A note beside the loop says four moves per song, but the loop makes five. Notes in code are called comments. Mina changes the five to a four, and Bo dances four moves.
1
How should Mina start reading Teo's code?
Skip to the middleLine by line from the top, saying what each line doesChange things and hope
2
A name in code, like beat count, is a clue to what a box holds.
TrueFalse
3
Notes in code that explain it to people are called .
commentsloopsboxes
4
Run this tiny program in your head. What does it say at the end?
7124
5
In the tiny program, which line gives the box coins its start value?
set coins to zeroadd three to coinssay coins
6
The computer reads a comment and changes the answer because of it.
TrueFalse
Match, order and fix
7
Join each line of the tiny program to its job.
1set coins to zero
2repeat four times
3add three to coins
4say coins
Aruns what is inside four times
Bchanges the box each time round
Cshows what the box holds
Dgives the box its start value
8
Put Mina's way of reading code in order.
Check the comment against the code
Try one small change
Start at the top
Run it on paper with small numbers
Look for names that are clues
9
A note says four moves per song, but the loop makes five. What should Mina do?
Trust the note and ignore the loopDelete the note and say nothingCheck the note against the code, because the code is what runs
10
Beat count starts at zero and goes up one each trip. After five trips it holds .
11
Circle every good way to read code.
Read one line at a timeSkip to the middleChange one thing at a timeTrust every comment
12
With a grown-up, take a recipe or a game's rules. Write what two of its lines do.
13
Draw the box called coins, and write what it holds after each of the four trips round the loop.
Scan the code at the top to mark this sheet on screenTake a photo of your answers or type them. It is marked for you automatically, and your score is kept.
Answer key · Set A
Mina reads Teo's code
1Line by line from the top, saying what each line does Read it like a recipe, one line at a time. Understanding comes before changing.
2True Good names are like labels on boxes.
3comments A comment explains why, but it can go out of date.
412 coins starts at 0 and gains 3 on each of four trips: 3, 6, 9, then 12.
5set coins to zero Set coins to zero means the box starts out holding zero.
6False A note is for people, so the computer skips it.
71-D, 2-A, 3-B, 4-C Each line has a role: start, repeat, change and show.
84, 5, 1, 3, 2 Read from the top, use the names, run it by hand, check the notes, then change one thing.
9Check the note against the code, because the code is what runs Comments can be out of date, and the code is what runs.
105 0, then 1, 2, 3, 4 and 5.
11Read one line at a time, Change one thing at a time Line by line and one change at a time keep it clear. Check comments against the code.
12Your own words: a grown-up reads it.
Mark each answer, count the right ones and write the score on the sheet.