Build a falling-stars game with many turtles, and tidy it step by step: from separate variables to lists, dictionaries and classes.
Each lesson works two ways. Students can work through the online tutorial at their own pace (it checks their answers and saves their progress in their browser), or you can teach it to the whole class from the slides, then send students into the tutorial for the Modify and Make steps.
Every lesson guide has plain-language notes, the answers to every check, a solution for every task, and slides and a worksheet for Waypoints Prepare. These guide pages are not linked from student pages, but they are not secret either: keep printed Teacher editions for answers you do not want students to find.
Whole-course cheat sheet: Open to print (every command, grouped by unit: a handout for the final challenge)
Many turtles at once, then lists and dictionaries to keep track of them.
Turtle() makes another turtle. Give it a name, star = Turtle(), and put the name and a dot in front of a command to give the command to that turtle: star.forward(50). Each turtle is an object: it keeps its own position, heading and colour. A command with no name in front goes to the default turtle, the one students used in the turtle course.
Once there are many objects, the program needs a way to keep track of them:
s1, s2, s3) work for three and cost the same block of code for every new one.{"turtle": s, "speed": 5, "points": 1}, read as star["speed"]. A list of dictionaries is a table: one row per star.Lists side by side are like a class roll and a separate list of phone numbers, matched by row. They work until someone joins the class and only one list is updated. A dictionary is a contact card: the name and the number stay on the same card.
s1.range(4) to range(8) and run it."colour": "orange" to the dictionary and colour each star with star["turtle"].color(star["colour"]).Cheat sheet: Open to print (A4, with a picture of what each command draws) · Markdown
Make your own kind of object with class, then give it methods: one line adds another star.
A class describes a new kind of object. class Star: says what every star stores and what every star can do. Star(100) makes one star; make four and you have four separate stars from one pattern.
__init__ (say "init") runs each time a star is made. Inside it, self is the star being made, and self.speed = 5 stores a speed in that star.star.speed, like a turtle's own commands.self as its first parameter: def move(self):. star.move() runs it for that star. Methods put each kind of object's behaviour in one place.This course stops there: no inheritance, getters and setters, or class diagrams.
star.move() and rock.touches(player) say what they mean.A class is a cookie cutter and each object is a cookie: same shape, but each one can have its own icing (its own values). Methods are like a vending machine's buttons: you press "give drink" and the machine knows how.
Where it breaks: the cookie cutter does not make cookies by itself. A class does nothing until Star(...) makes an object, and its methods do nothing until they are called.
Pet("Rex", 4) to another pet and print its name.self. from self.speed = ... in Lesson 4's game and run it: read the AttributeError.print("caught") inside a new method catch(self) and call it when a star is caught.self is the name for "the star this method was called on".__init__? Python's names for special methods have them. __init__ is the one Python runs when an object is made.Cheat sheet: Open to print (A4, with a picture of what each command draws) · Markdown