Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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, gun):
        """Create a Turret instance...