+ 2
Can not find a mistake.
Hello everyone, I need a help, I can not find a mistake (maybe some mistakes). This is text of task: We are working on a game. Our Player class has name and private _lives attributes. The hit() method should decrease the lives of the player by 1. In case the lives equal to 0, it should output "Game Over". Complete the hit() method to make the program work as expected. This is my code: class Player: def __init__(self, name, lives): self.name = name self._lives = lives def hit(self): #ваш код if self._lives > 0: self._lives = self._lives - 1 if self._lives <= 0: print("Game over") #print(self._lives) p = Player("Cyberpunk77", 3) p.hit() p.hit() p.hit()
7 Answers
+ 3
Lyapunov Alexander , you have a typo => "Game over" should be "Game Over".
+ 2
You can change the print(self._lives) to another line after the modified variable.
+ 2
Yes, you are right. Line "print(self._lives)" to need just for checking.
I have corrected text of program and now this line is commentary.
But, could you say, where is the mistake?
+ 2
Seems no if the input is limited.
What's the sample input and output ?
What's the wrong prompt?
+ 2
Your prog does work...but there's not need to check for "<= 0", just do:-
if self._lives > 0:
self._lives = self._lives - 1
else:
print("Game over")
+ 2
TheWh¡teCat 🇧🇬
Exactly, this code works.
+ 1
Thank you everyone, but internal test does not pass (