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

str method producing weird things on attack

Hi!

When running this game, I get an odd print out when the monster attacks. Namely, I get the formatted text regarding the monster and then "<built in method of lower of str object at ....>'

Then the console does not move on to ask the question regarding dodging. I figure there's something wrong in the calls inside monster_turn but I can't find it. Help?

Here's my monster_turn() - def monster_turn(self):

if self.monster.attack():
    print("{} is attacking!" .format(self.monster))
    if input("Dodge? Y/N" .lower) == 'y':
      if self.player.dodge():
        print("You dodged!")
      else:
        print("You got hit anyway")
        self.hit_points -= 1
    else:
        print ("{} hit you for 1 point" .format(self.monster))            
        self.hit_points -= 1
else:
  print ("{} isn't attacking this turn" .format (self.monster))

1 Answer

Gianmarco Mazzoran
Gianmarco Mazzoran
22,076 Points

Hi,

there's a couple of errors in your code.

See the comments in this code:

if self.monster.attack():
    print("{} is attacking!".format(self.monster))
    if input("Dodge? Y/N").lower() == 'y': # call the function .lower() outside the input
          if self.player.dodge():
          print("You dodged!")
        else:
          print("You got hit anyway")
          self.player.hit_points -= 1 # you need to target the player's hit_points
    else:
        print ("{} hit you for 1 point".format(self.monster)) # pay attention to the space     
        self.player.hit_points -= 1 # same here
else:
  print ("{} isn't attacking this turn".format(self.monster)) # pay attention to the space