Preservation challenge (intermediate Python - 23.2)
I feel like I'm close, but I can't seem to get the lives to decrease with each method call. I've also tried self._lives -= 1 (my initial idea), but it says 'invalid syntax'. After that I considered using an operator overload definition to define '-=', but after a few attempts I got confused as to how to input that, and usually when I start doing stuff like that it turns out the solution was much simpler than what I was attempting to pull off aha. Gotten the same output, 3 '2's with a while loop, but yield caused some <generator> error so I abandoned that. And I don't think it should require a loop? Anyways, here's my code, 'tips/directions' > 'handing me the answer'!: class Player: def __init__(self, name, lives): self.name = name self._lives = lives def hit(self): #your code goes here if self._lives==0: print("Game Over") else: return self._lives-1 p = Player("Cyberpunk77", 3) print(p.hit()) print(p.hit()) print(p.hit())