From the course: Python: Programming Efficiently

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Challenge: Bale of turtles

Challenge: Bale of turtles - Python Tutorial

From the course: Python: Programming Efficiently

Start my 1-month free trial

Challenge: Bale of turtles

(upbeat music) - [Instructor] For your challenge, I'm asking you to extend our graphical programming language, by writing a new class bale, that represents a group of n turtles. An instance of the bale class, we'll take the usual commands, forward, back, left, and right, and pass them onto the turtles. Either with a common argument, or by giving a list or iterator that specifies the argument for each turtle. Here's an example of code that uses bale. We create a group of five turtles in our terrarium. We instruct them to turn each by a different angle, and we tell them to move forward, all by the same distance. And here's the result, where I have drawn each turtle with a different color. A hint, to figure out whether a given argument is a sequence, or an iterator, or just a number you can use the abstract base class iterable from collections.abc. When I check for example, whether a list is an instance of iterable,…

Contents