[Tutor] class with objects

Wayne srilyk at gmail.com
Sun Oct 11 22:00:01 CEST 2009


On Sun, Oct 11, 2009 at 2:42 PM, shellcom3 at juno.com <shellcom3 at juno.com>wrote:

> I want to display the ship default value for zero and display the ship's
> initial fuel level. Also have a method called status that displays an
> object's name and  fuel values. I want to have several Ship objects and call
> their status() methods to test various aspects of the class constructor.
>

And what problems have you run into? What would you like from us? This
sounds vaguely like homework which we don't do here. We are, however, more
than happy to offer pointers in the right direction if you get stuck.

For an explanation of /how/ to ask a good question, check out this:
http://catb.org/~esr/faqs/smart-questions.html#examples

HTH,
Wayne


>
> Here's my code:
>
>                   class Ship(object):
>    """A spaceship"""
>    total = 0
>    def __init__(self, name, fuel = 0):
>
>        print "My spaceship has arrived! The",name
>        self.name = name
>        self.fuel = fuel
>
>        print "My fuel level is", fuel
>
>    def status():
>        Ship.total += 1
>        print "The total number of objects is", Ship.total
>    status = staticmethod(status)
>
> #main
> ship = Ship("Galaxia")
>
> print "\nCreating objects."
> ship1 = Ship("object 1")
> ship2 = Ship("object 2")
> ship3 = Ship("object 3")
> Ship.status()
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091011/32cb7ad4/attachment.htm>


More information about the Tutor mailing list