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 Object-Oriented Python (retired) Hack-n-Slash The Final Push

Mollie Pettit
Mollie Pettit
750 Points

Goblin object not callable

I am having trouble with a particular line. It is the line that reads:

print("{} dodged your attack!".format(self.monster()))

within the player_turn section (pasted below). If I change this line to:

print("They dodged!")

the code then works perfectly fine. So this is the only line that is giving me issues. Any thoughts?

def player_turn(self):
    player_choice = input("[A]ttack, [R]est, [Q]uit?)").lower()
    if player_choice == 'a':
        print("You're attacking {}!".format(self.monster))

        if self.player.attack():
            if self.monster.dodge():
                print("{} dodged your attack!".format(self.monster()))
            else:
                if self.player.leveled_up():
                    self.monster.hit_points -= 2
                else:
                    self.monster.hit_points -= 1
                print("You hit {} with your {}!".format(self.monster, self.player.weapon))
        else:
            print("You missed!")
    elif player_choice == 'r':
        self.player.rest()
    elif player_choice == 'q':
        sys.exit()
    else: 
        self.player_turn()

1 Answer

Peter Lawless
Peter Lawless
24,404 Points

Leave off the () at the end of self.monster and give it a try?