Class Work
Topic 7-1: Square Bunny Hop
The purpose of this exercise is to use definite loops in a program.
This exercise is based on exercise 2 on page 197 from the Learning to Program with Alice textbook.
Square Bunny Hop. This exercise explores the use of nested loops. Anything can be placed inside a loop, including other loops. This creates a nested loop. The goal of this exercise is to use loops to to have a rabbit hop in a square pattern. The initial world simply has a bunny in it. The bunny has a class level method, hop, already completed. Use a loop to make the rabbit hop three times. This is one side of the square. When the loop ends turn the bunny one quarter revolution left. Tests this portion to ensure it works. To have the bunny hop in a square place the initial loop and the turn into another loop that repeats these actions four times.
Here is an outline of the program
Loop 4 times |
Click here to download the initial Alice world.
How many total hops does the bunny take?
Change the program so the length of one side of the square is 5 hops instead of 3. How many total hops does the bunny take now?
Change the program so the bunny performs a square pattern, then a pentagon (5 sides) pattern, then a hexagon pattern (6 sides), then a heptagon pattern (7 sides), and finally an octagon pattern (8 sides). As an extra challenge make it so this is done with 3 nested loops.