[Tutor] designing POOP

bhaaluu bhaaluu at gmail.com
Fri Feb 8 20:54:45 CET 2008

On Feb 7, 2008 9:40 PM, Tiger12506 <keridee at jayco.net> wrote:
> There's a couple of errors in here that no one has addressed yet because the
> question was geared towards programming style... So now I will address them.
> Or undress them, I suppose. ;-)

I didn't make much progress until I started thinking
about the Explorer and Light classes as actual objects.

I've tried to address what you undressed. 8^D
Here is another version to undress:


import time

class Explorer(object):
    def __init__(self,name):
        """initilaization method"""
        self.__name = name
        self.strength = 20
        self.wealth = 60

    def get_name(self):
        return self.__name

class Light(object):
    """light switch"""

    def __init__(self,light):
        self.light = light

    def state(self):
        if self.light == 0:
            print (" IT IS TOO DARK TO SEE ANYTHING")
            print (" THE LIGHTS ARE ON, BUT NO ONE'S HOME")

def cs():
    print "\n"*50

def main():
    tally = 0
    switch = Light(0) #instance
    cs() # clear screen
    name = raw_input(" WHAT IS YOUR NAME, EXPLORER? ")
    explr = Explorer(name)
    while True:
        cs() # clear screen
        print (" %s, YOUR STRENGTH IS %d" % (explr.get_name(), explr.strength))
        print (" YOU HAVE $%d" % explr.wealth)
        answer = raw_input(" WHAT DO YOU WANT TO DO? [Q|L]: ")
        if answer.upper() == "Q":
        if answer.upper() == "L":
                if switch.light == 1:
                    switch.light = 0
                    switch.light = 1
                    explr.strength -= 5
                    explr.wealth -= 15
                    if explr.wealth <= 0:
                        print (" YOU HAVE NO MONEY")
                    if explr.strength <= 0:
                        print (" YOU DIED...")
            print (" INVALID CHOICE")
        tally += 1
    print (" FINAL SCORE:")
    print ("    TALLY: %d" % tally)
    print (" STRENGTH: %d" % explr.strength)
    print ("   WEALTH: $%d" % explr.wealth)

if __name__ == "__main__":

Happy Programming!
b h a a l u u at g m a i l dot c o m
"You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul." [Mahatma Gandhi]

More information about the Tutor mailing list