[Tutor] class with objects
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:
> 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)
> ship = Ship("Galaxia")
> print "\nCreating objects."
> ship1 = Ship("object 1")
> ship2 = Ship("object 2")
> ship3 = Ship("object 3")
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor