(Python)Do you see loop in this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

20th Dec 2021, 8:25 AM
Lea
Lea - avatar
4 Answers
+ 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
21st Dec 2021, 2:45 AM
A͢J
A͢J - avatar
+ 2
There is not any loop but there is recursion. function calling itself many times.
20th Dec 2021, 9:03 AM
A͢J
A͢J - avatar
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ It works now!!! Thank you!
21st Dec 2021, 5:01 AM
Lea
Lea - avatar
0
How could I imporve my code?
20th Dec 2021, 9:47 AM
Lea
Lea - avatar