Copy the code shown at the end of the video into the code editor.
Then modify such that it will draw an octagon with a side of length 20.
Make sure your code is working correctly before completing the step. Use the hints available only if you need to.
Hint 2-1: changes needed
Hint 2-2: the complete code
Notes
Total hints used: /
Step 3: Draw a circle, centred on the display
(There is no video for this step.)
Change the code again so that it draws a circle that fits within the display and is centred within in.
Make sure your code is working correctly before completing the step. Use the hints available only if you need to.
Hint 3-1: changes needed
Hint 3-2: the complete code
Notes
Total hints used: /
Step 4: create a circle procedure
Get your code to the same state as that shown at the end of the video (if necessary replaying the video and pausing),
and test that it draws two concentric circles of different radius. Then:
Delete the second call to the circle procedure - as the random walk simulation needs only one.
Insert, immediately after the definition of t within the main routine the instruction:
call circle(t, 50)
and run the program again.
Does hiding the Turtle affect what it draws?
Hint 4-1: the complete code
Notes
Total hints used: /
Step 5: draw a random walk
Notes
Total hints used: /
Step 6: count the paces
Get your code to the same state as that shown at the end of the video (if necessary replaying the video and pausing),
and test that it works correctly.
Run the program 10 times, and record here the smallest, and the largest, number of paces taken to reach the edge
of the circle.
Notes
Total hints used: /
Step 7: simulate multiple walks
Get your code to the same state as that shown at the end of the video (if necessary replaying the video and pausing),
and test that it works correctly.
What value did you get for the average number of paces?
Try increasing the number of walks from 20 to 100, noting that you will have to change 20 to 100 in two separate places.
What value did you get for the average number of paces after 100 walks?
The fact that we had to change the 20 to 100 in two locations is an example of breaking what
principle of good programming?
What would be a simple way to improve the code so that you could change the number of walks
required in just one place?
Notes
Total hints used: /
Congratulations! You have completed this worksheet
If you have time, try any of the following:
Simulate a larger number of walks e.g. 100. This will give a more accurate figure for the average number of paces.
Make the pace smaller but keep the circle's radius the same size as now.
The average number of paces to reach the edge will be larger. But does it increase in proportion? Try
three different values and plot the average against pace size.
Go back to the original values, but make a small change to the range of possible turn-angles between paces:
-60 to + 60 degrees, or -120 to + 120, say.
How does this change the average number of paces? Is the relationship linear?
Read more about the nature and application of Random Walks on Wikipedia.