Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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 68,423 Points

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

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 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!