Math Bonk! Learning Centre Play the game

Worksheet for the lesson Coding with Nested Events and Subprograms · All worksheets

Coding with Nested Events and Subprograms

Grade 7 math worksheet · mathbonk.com/learn

Name: ______________________   Date: ____________

Look

Shape drawn by a loopSidesTurn at each corner
Triangle3120°
Square490°
Pentagon5
Hexagon6
A table of shapes drawn by a repeat loop, with two turn angles missing
  1. What turn at each corner draws a regular pentagon?
  2. What turn draws a regular hexagon?
  3. What shape does repeat 8 [move 10; turn 45] draw?

Practice

  1. repeat 4 [repeat 6 [stamp]]. How many stamps in all?
  2. repeat 5 [move 10; turn 72]. What shape is drawn?
  3. repeat 6 [move 10; turn ?]. What angle draws a regular hexagon?
  4. A subprogram called "square" runs 4 "move" blocks. It is called 8 times. How many moves in all?
  5. repeat 4 [move 5; turn 90]. What is the perimeter of the shape drawn?
  6. How many degrees are in a full turn?
  7. A regular octagon needs a turn of how many degrees at each corner?
  8. repeat 2 [repeat 10 [flip a coin]]. How many flips in all?
  9. A fair coin is flipped 100 times. About how many heads would you expect?
  10. Why use a subprogram instead of copying the same blocks five times?
  11. In repeat 2 [repeat 6 [stamp]; turn], which block runs exactly 2 times: stamp or turn?

Think it through

  1. Draw the shapes made by repeat 6 [move 10; turn 60] and by repeat 3 [move 10; turn 120].
  2. Explain why a subprogram makes code easier to fix.

Challenge

  1. repeat n [move 8; turn 40] draws a regular polygon. What is n, and what is the perimeter of the shape?
  2. A subprogram uses 10 blocks and is called 12 times. How many blocks run in total?

Answer key

Look

  1. 72°
  2. 60°
  3. A regular octagon

Practice

  1. 24
  2. a regular pentagon
  3. 60°
  4. 32
  5. 20
  6. 360
  7. 45°
  8. 20
  9. 50
  10. it is shorter, and one change fixes every use
  11. turn

Think it through

  1. A hexagon and a triangle
  2. You change it once and every place that uses it is fixed

Challenge

  1. n is 9 {= 360/40}; the perimeter is 72 units
  2. 120