+ 1
Intermediate Python- 25.2 Practice help - âStaying aliveâ
Please help, thanks! We are improving our game and need to add an isAlive property, which returns True if the lives count is greater than 0. Complete the code by adding the isAlive property.
9 RĂ©ponses
+ 6
You're missing to add isAlive property.
@property
def isAlive(self):
if self._lives > 0:
return True
+ 2
+ 1
Zach Z
Where is your attempts?
+ 1
â©âźâ
âźâ© , Simba , ChaoticDawg , AÍąJ , JaScript You all have been super helpful, same as the other question i just tagged, can one of you help here? Thanks!
+ 1
This will help you:
https://code.sololearn.com/cvXD6VuAI9D8/?ref=app
+ 1
class Player:
def __init__(self, name, lives):
self.name = name
self._lives = lives
def hit(self):
self._lives -= 1
#your code goes here
@property
def isAlive(self):
if self._lives > 0:
return True
p = Player("Cyberpunk77", int(input()))
i = 1
while True:
p.hit()
print("Hit # " + str(i))
i += 1
if not p.isAlive:
print("Game Over")
break
0
Code:
class Player:
def __init__(self, name, lives):
self.name = name
self._lives = lives
def hit(self):
self._lives -= 1
p = Player("Cyberpunk77", int(input()))
i = 1
while True:
p.hit()
print("Hit # " + str(i))
i += 1
if not p.isAlive:
print("Game Over")
break
0
Code is there