+ 2
(Python)Do you see loop in this code?
I didn’t put any loop in my code, but if you run it, it says “line 16 repeated 993 times….why? https://code.sololearn.com/cx3juFCDJbCd/?ref=app
4 Antworten
+ 2
Lea
Change this:
@isAlive.setter
def isAlive(self, lives):
if self._lives >= 1:
self.isAlive = True
else:
self.isAlive = False
To this: Program says if lives is > 0 then return True
@property
def isAlive(self):
if self._lives > 0:
return True
else:
return False
Remove this code which is a reason for recursion:
@property
def isAlive(self):
return self.isAlive
remove this from init function
self.isAlive = True
+ 2
There is not any loop but there is recursion. function calling itself many times.
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ It works now!!! Thank you!
0
How could I imporve my code?