Sunday, July 13, 2025
Coding Education STEM

“Rabid Racoon” tracking (Python, using our own class)- Part 2

This is part 2 of the original series on Rabid Racoon. Please read Part 1 first to follow along.

So, this time we’ll use a real-time graphing method using Python’s Turtle library instead of scatter plot as we did in Part 1. The beautiful part is, since we already created our custom Class in Part 1, our new code is going to be extremely small with no change needed in the Class code.

So, let’s create a new .py file for this code (without even touching our Class code file. Remember the name where the Class code lives and its Class name as before).

The Code:

Just as before, we import random and our Class. But we also import turtle library as you see above for real-time graphics. Note, that I called TakeAWalk() passing it argument of 50 this time. Rest of the code has relevant comments starting with ‘#’.

The Output:

Here’s a sample animation of the output being generated from above code.

Hope you have fun with this! Happy coding 🙂

BONUS: By adding the following line, I generate the final label with exactly how many points were “walked” by the racoon at the end of animation:

Back To Top