Remember: A for loop repeats the lines pushed in under it. Range says how many turns, and lines not pushed in run just once.
Read and answer
Read the story, then answer.
One line, many wavesMina is Bo's coder, and Bo will open Friday's robot show with a wave. Mina wants five waves, but typing the same wave line five times makes her fingers ache, and one line has a typo. Ms Ola shows her a shorter way: a loop. She writes one line that starts with for, and range says how many turns there are. The wave line sits underneath, pushed in a little, so it belongs to the loop. Range of five counts zero, one, two, three and four, which is five numbers, so Bo waves five times. Mina changes only the five to an eight, and Bo waves eight times. Then she adds a bow line that is not pushed in, so it runs just once, after the last wave.
1
Bo runs this loop. How many times does he wave?
4 times5 times6 times
2
Range says how many the loop takes.
turnslinesquotes
3
A line pushed in under the for line is inside the loop.
TrueFalse
4
Mina changes only the five to an eight. How many waves now?
8 wavesStill 5 waves1 wave
5
Range of five counts one, two, three, four, five.
TrueFalse
6
How many times does the Bow line run in this show?
Four timesEight timesJust once
Match, order and fix
7
Join each piece to its job.
1for
2range
3a line pushed in
4print
Astarts a loop
Bshows a message
Cbelongs to the loop
Dsays how many turns
8
Mina gets her waves. Put the story in order.
Bo waves five times
Mina writes for and range of five
Ms Ola shows her a loop
Mina types the same wave line again and again
9
Mina wants Bo to bow just once, at the end. What is the mix-up to fix?
The bow line is pushed in, so it repeatsThe range should be oneThe wave line should not be pushed in
10
In the show program above, Bo waves and spins times each.
11
Counting every print in that show program, the screen shows messages in all.
12
Write what Mina changes so Bo waves twenty times.
13
Draw Bo's arm for each turn of range(3).
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
Bo's five waves
15 times Range of five counts zero, one, two, three and four, which is five numbers, so the loop turns five times.
2turns Each number that range counts is one turn of the loop.
3True Only the lines pushed in belong to the loop, and they run on every turn.
48 waves The loop follows whatever number range holds, so range of eight means eight waves.
5False Range of five counts zero, one, two, three and four. That is still five numbers.
6Just once The Bow line is not pushed in, so it is not in the loop. It runs once, at the end.
71-A, 2-D, 3-C, 4-B For starts the loop, range counts the turns, pushed-in lines are inside it, and print shows a message.
84, 3, 2, 1 Mina's fingers ache first, then Ms Ola shows the loop, then Mina writes it, and then Bo waves.
9The bow line is pushed in, so it repeats A pushed-in line is inside the loop. Move the bow line back to the edge and it runs once, after the loop.
104 The for line says range of four, and both pushed-in lines run on every turn.
1110 Show starts runs once, wave runs four times, spin runs four times and Bow runs once, and 1 + 4 + 4 + 1 = 10.
12Your own words: a grown-up reads it.
Mark each answer, count the right ones and write the score on the sheet.