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 - Python Tutorial
From the course: Python: Programming Efficiently
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,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Object-oriented and functional Python1m 51s
-
(Locked)
Divide and conquer with Python classes6m 35s
-
(Locked)
Exploit class inheritance5m 58s
-
(Locked)
Functional techniques in Python6m
-
Function decorators5m 31s
-
(Locked)
Challenge: Bale of turtles2m 29s
-
(Locked)
Solution: Bale of turtles3m 8s
-
(Locked)
-
-