Spaceship objects
Posted
by Jam
on Stack Overflow
See other posts from Stack Overflow
or by Jam
Published on 2010-03-23T14:16:56Z
Indexed on
2010/03/23
14:53 UTC
Read the original article
Hit count: 347
I'm trying to make a program which creates a spaceship and I'm using the status() method to display the ship's name and fuel values. However, it doesn't seem to be working. I think I may have messed something up with the status() method. I'm also trying to make it so that I can change the fuel values, but I don't want to create a new method to do so. I think I've taken a horrible wrong turn somewhere in there. Help please!
class Ship(object):
def __init__(self, name="Enterprise", fuel=0):
self.name=name
self.fuel=fuel
print "The spaceship", name, "has arrived!"
def status():
print "Name: ", self.name
print "Fuel level: ", self.fuel
status=staticmethod(status)
def main():
ship1=Ship(raw_input("What would you like to name this ship?"))
fuel_level=raw_input("How much fuel does this ship have?")
if fuel_level<0:
self.fuel=0
else:
self.fuel(fuel_level)
ship2=Ship(raw_input("What would you like to name this ship?"))
fuel_level2=raw_input("How much fuel does this ship have?")
if fuel_level2<0:
self.fuel=0
else:
self.fuel(fuel_level2)
ship3=Ship(raw_input("What would you like to name this ship?"))
fuel_level3=raw_input("How much fuel does this ship have?")
if fuel_level3<0:
self.fuel=0
else:
self.fuel(fuel_level3)
Ship.status()
main()
raw_input("Press enter to exit.")
© Stack Overflow or respective owner