20.17 Exercises

From Foundations of Python ProgrammingGNU FDL 1.3Original pagePython1 class period2 exercises1 graded test

README.md

20.17 Exercises

Read first in the book: 20.8 Instances as Return Values, 20.9 Sorting Lists of Instances, 20.10 Class Variables and Instance Variables, 20.11 Public and Private Instance Variables, 20.12 Thinking About Classes and Instances, 20.13 Testing classes, 20.14 A Tamagotchi Game, 20.15 Class Decorators, 20.16 Glossary.

Exercise 1

Add a method reflect_x to Point which returns a new Point, one which is the reflection of the point about the x-axis. For example, Point(3, 5).reflect_x() is (3, -5)

Open the 01 folder and edit main.py. This one is not graded, so check it yourself.

Exercise 2

Add a method called move that will take two parameters, call them dx and dy. The method will cause the point to move in the x and y direction the number of units given. (Hint: you will change the values of the state of the point)

Open the 02 folder and edit main.py. Run Tests checks it.

For teachers

20.17 Exercises

Students read Foundations of Python Programming's “Exercises” in CS Room and work through its 2 Python coding exercises (1 graded).

  • Time: 1 class period
  • Tests: 1 in 1 graded exercise, set up for you when you import the lesson

Reading first

Exercises

FolderGradingTests
01Not graded; students check it themselves0
02Autograded1