why this is giving syntax error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why this is giving syntax error?

class Spam: def __init__(self,name,lives): self.name = name self.lives = lives def hit(self): if self.lives > 0: return self.lives = self.lives -1 elif self.lives == 0: return 'Game Over' play = Spam('Cyber',10) print(play.hit()) this gives syntax error at line 7 pointing at = sign

6th May 2022, 3:04 PM
Tarun
3 Answers
+ 2
You cannot assign in the return statement. Decrease lives first, then return self.lives
6th May 2022, 3:11 PM
Lisa
Lisa - avatar
+ 2
Lisa , you are right, i have removed my post - sorry
6th May 2022, 5:50 PM
Lothar
Lothar - avatar
0
thankyou
6th May 2022, 4:14 PM
Tarun