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.
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()
____________________________________________________________
Find Top-Rated Pavers
Get competing bids on any driveway, patio or walk need. Free quotes!
http://thirdpartyoffers.juno.com/TGL2141/c?cp=mcvPp46j2ooOnKJe4-1LngAAJ1CmHaRKpeX3s0f3JfT8odq8AAQAAAAFAAAAALpJjD0AAANSAAAAAAAAAAAAAAAAABIXaQAAAAA=
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor