Random Walk
This program will give you practice with while loops, user input and random. Thanks to Stuart Reges at University for the original idea – yes, this is a college-level assignment!!
In this program, you will be simulating a “random walk” from the center of a circle out to its perimeter. Read more about random walks on Wikipedia. You will produce output like the following:


Your program should allow the user to produce multiple walks. Here is a sample interaction:
Radius? 50 I escaped in 2468 move(s). Walk again (yes/no)? yes
Radius? 35 I escaped in 987 move(s). Walk again (yes/no)? yes
Radius? 100 I escaped in 13713 move(s). Walk again (yes/no)? no
Total walks = 3
Total steps = 17168
This interaction should have drawn three different random walks on the
same window, erasing in between each run (you may want to use the
clear() function). You may assume that users type in integers when
prompted for a radius and a string when prompted whether or not to
play again.
Hints
- Use a while loop to do repetition. There is a distance function that takes in an x and y coordinates and gives the turtle’s distance from those coordinates.
- Start by writing a program that just performs a single random walk (doesn’t prompt the user to repeat)
- Test with small radius values so it doesn’t take forever
- My solution uses 3 functions and is about 50 lines
- You may want to send a value out of a function. Read this document on return statements.
Extensions
- Make each step a random color (like the random activity you did)
- Change color every 15 steps (use the mod % operator)
- Calculate more statistics — report the best walk, report the average steps per pixel, etc.






