Python

I get <bound method Warrior.attack of <characters.Warrior object at 0x7faec4faa780>> when trying to run my methods.

Here is my code:

        class Character:
            def __init__(self, name, **kwargs):
                self.name = name

                for key, value in kwargs.items():
                setattr(self, key, value)


        class Warrior(Character):
            courage = True

            def attack(self):
                return self.courage and bool(random.randint(0, 1))

            def defend(self, shield_level):
                return self.courage and shield_level > 4 

I created a different character type but tried to do the exact equivalent of what Kenneth did. Any help would be appreciated. Thanks in advance!

[MOD: need to use ``` instead of ‘’’ in formatting -cf]

I also can't figure out why the character class won't show up as code.

Chris Freeman
Chris Freeman
Treehouse Moderator 59,730 Points

need to use backtick ``` instead of quotation marks ’’’ in formatting -cf]

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 59,730 Points

Be sure you are calling the method by including parens: instance.attack() verses referencing the method without parens.

Post back if you need more help. Good luck!!!

Thank you, Chris! I got defend to work now, but attack is having trouble with the name 'random' not being defined.

Oh yes, I do remember that being in there now. Thank you!