In this chapter, we explored the implementation of our own data types by creating classes. The programmer can take advantage of this ability to create solutions using a data model that closely resembles the problem domain. Classes provide a description of objects (instances of classes) by defining data and methods. Objects are created by calling the constructor method.
Other methods, both accessors and mutators, allow the programmer to communicate with individual objects. We also introduced a number of special methods defined by Python, which in some cases are bound to operators. Finally, we used the Turtle
to implement a graphical simulation of planetary movement.
10.1 Modify the SolarSystem
class to support more than one sun.
10.2 Modify the Planet
class so that the planet does not have the instance variables for x
and y
but simply uses the x
and y
location stored in the turtle.
10.3 Research n-body simulations. Using the ideas from this chapter, implement your own simple n-body simulation.
Design Credits: Calculator Icon made by Smashicons from www.flaticon.com
3.141.165.120