O'Reilly logo

Sage Beginner's Guide by Craig Finch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - creating your first module

Create a new Python file called tank.py that contains the following code:

 import sage.all class Cannon(): """Model of a large cannon.""" def __init__(self, damage): """Create a Cannon instance Arguments: damage Integer that represents the damage inflicted by the cannon """ # _damage amount of damage inflicted by cannon (integer) # _operational True if operational, False if disabled self._damage = damage self._operational = True def __str__(self): return 'Damage value:' + str(self._damage) class Track(): """Model of a continuous track.""" def __init__(self): # _operational True if operational, False if disabled self._operational = True class Turret(): """Model of a tank turret.""" def __init__(self, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required