Programming Challenges for Python Turtle
February 14, 2023 9:36 AM   Subscribe

I have a group of about six programmers who are way too experience for the basic Python units in my high school Intro to Comp Sci class. I'd like to give them challenges to take on over a few weeks. Ideally these would require some skill in Python and some idea of more fundamental issues in design and algorithm.

It would be ideal if we used the Turtle library in Python — just one or more sprites, pen down or up.

So far, I have:
-- Draw a Sierpinski triangle to an arbitrary depth.
-- Implement the BOIDS algorithm for flocking behavior.

And that's what I got. Help?
posted by argybarg to Computers & Internet (9 answers total) 2 users marked this as a favorite
 
What do the "basic Python units" cover? Are you only interested in visual/drawing problems? Have they done basic searching and sorting algorithms?
posted by number9dream at 9:46 AM on February 14, 2023


Response by poster: These students are solid with control structures, lists, functions and return values, variables, and some concepts on objects and classes. They have not done basic searching and sorting, but most of them did in Java (they're returning from my AP programming class, slumming in the intro class — nothing I can do about it except give them challenges).

I'd like for them to work with Turtle because the rest of the class is.
posted by argybarg at 9:56 AM on February 14, 2023


Response by poster: And I know a good solid fundamental algorithms class would be good for them, but I have 19 other students, programming for the first time, to work with while the more advanced students plug away on their own. I suspect they would plug away at CS Fundamentals in a desultory way.
posted by argybarg at 9:57 AM on February 14, 2023


Do they know enough that you could make them implement (a basic version of) Turtle? (With extra credit for more features?)
posted by trig at 9:59 AM on February 14, 2023 [1 favorite]


I'm trying to think of ideas that use Turtle to help introduce them to other useful Python stuff.

For example, read a list of coordinates from a text file and then make the turtle follow the path defined by the coordinates. Not too difficult, but now they know how to do file I/O.

For object-oriented stuff, you could have them implement subclasses of Turtle that have funny behaviors. For example, a dizzy turtle (was going to say "drunk" but that's clearly not appropriate for the context) that adds a random 0-10 degree turn before every movement. Or a mirror turtle that turns left when you say to turn right, goes backward when you say to go forward, etc. Or a mapping turtle that records its stopping points in a text file. All these things would require them to override methods from the parent Turtle class.

I'm not familiar with Turtle and what it can do, but maybe there are other ways you can use the library to illustrate other general programming concepts without making it seem like a boring intro class.
posted by number9dream at 10:11 AM on February 14, 2023 [1 favorite]


Maze running can get as complicated as you like, yes? Lots of ways to learn efficiency trade offs too.
posted by clew at 12:03 PM on February 14, 2023 [1 favorite]


Perhaps there are enough ingredients to make basic real-time games:

e.g. for "space invaders", you'd need: draw sprites on screen (put that turtle to work stamping out sprites?), game loop measuring the 'delta_t' frame duration (standard library time + while loop), reading keyboard state without pausing to get player input (???), basic numerical integration to animate sprites (next_pos = pos + delta_time * velocity), enough knowledge of lists/arrays to manage the state of a collection of space critters/projectiles/etc, a splash of logic to figure out collision detection and incredibly basic enemy AI, then enough time to tinker and get everything to kind of work.

For "asteroids", all the above, plus splashes of 2d vector math & trigonometry since the sprites can move in any direction, not just locked to four.

There's a huge number of possibilities for extension projects, depending on what students are interested in creatively or technically (realise their vision of a completely novel game using these building blocks; improve the AI; add ridiculous particle effects; add sound effects and music; make the music change react to what is happening; replace the basic euler integration method with something more energy-conserving (leapfrog?); learn C then rewrite it in C and SDL; add networking to make it 2 player over the internet; rework it as a turn-based multiplayer game with hot-seat multiplayer or or play by email)
posted by are-coral-made at 1:03 PM on February 14, 2023 [1 favorite]


spirograph!! I think having an way to programmatically change the color of the pen, and the angle, and the length to draw a shape would be about level-appropriate. In general, graphs in polar coordinates typically have a straightforward implementation but make some cool pictures.

And I've seen a Python training class that used turtle to implement the old "Snake" game from old-school cell phones :) Very cool, but iirc it means you have to have some objects like the "head" of the snake, etc. I'm not sure if that's more than you had in mind.
posted by adekllny at 1:07 PM on February 14, 2023 [1 favorite]


Recreate Benoit Mandelbot?
posted by humbug at 4:42 PM on February 14, 2023 [1 favorite]


« Older Shoulder pain: Orthopedist or physical therapist?   |   NYC novice needs to go from Times Square to... Newer »
This thread is closed to new comments.