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
3 Antworten
+ 2
You cannot assign in the return statement. Decrease lives first, then return self.lives
+ 2
Lisa ,
you are right, i have removed my post - sorry
0
thankyou