Exercises for Lesson 21

Back to Lesson 21

Exercise 1: Inheritance and method calls

Let’s dive into graphics.py, which is a fantastic example of object-oriented design.

Part a: Family trees

There are over 10 classes related to shapes and the window. Make a diagram just showing the parent-child relationships between classes in graphics.py.

Part b: Circle.draw

Using your diagram, look through different class definitions. In which class is the .draw() method of a Circle defined?

Part c: Circle.getCenter

Using your diagram, look through different class definitions. In which class is the .getCenter() method of a Circle defined?

Back to Lesson 21

Exercise 2: Bin packing

Consider the following set of activities, more generally labeled with letters as names:

    A: 2 hours
    B: 2 hours
    C: 2 hours
    D: 2 hours
    E: 3 hours
    F: 4 hours
    G: 5 hours

Part a: Three bins

Give a valid assignment of these activites to three bins, each of size 10.

Part b: Two bins

Give a valid assignment of these activities to two bins, each of size 10.

Part c: Complexity

What is the number of possible assignments of these seven activities to two bins, assuming we assign each activity to exactly one bin?

Back to Lesson 21