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

Camille Ferré
Camille Ferré
3,330 Points

Why do we have self.monster or self.monsters in the __init__ ?

Hi all,

I have a quick question I can't seem to find the answer to.

In the init method, we say: while the player has hit_points and there is a monster --> play

I don't understand while the part "There is a monster" is written "self.monster or self.monsters" since both are linked and self.monster is the current monster we are playing with, it will only be empty if there are no more self.monsters.

What could be a case where self.monster is empty but there are self.monsters ? In this case the problem would come from the method get_next_monster ?

Thanks a lot for your help

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

To clarify, the attributes self.monster and self.monsters are not the same. Attribute self.monsters (plural) is created in the setup() method and is assigned a list of monsters. Attribute self.monster (single) is also created in the setup(), and also in get_next_monster() method, it is assigned a Monster popped off of the self.monsters list or None.

There is a sliver of time, during setup() where self.monsters has been assigned, but self.monster is empty, but that would not apply to the if statement you reference.

As get_next_monster() pops the last Monster from the self.monsters list, self.monster will be non-None, but self.monsters will be an empty list.

So you are correct that in the if conditional check, there is not a time when self.monster is empty and self.monsters is not empty. The would mean the code "or self.monsters" is unnecessary.