0

Whats wrong on this code? Why it outputs "None"?

class Enemy: name = "" lives = 0 def __init__(self, name, lives): self.name = name self.lives = lives def hit(self): self.lives -= 1 if self.lives <= 0: print(self.name + ' killed') else: print(self.name + ' has '+ str(self.lives) + ' lives') class Monster(Enemy): def __init__(self): super().__init__('Monster', 3) class Alien(Enemy): def __init__(self): super().__init__('Alien', 5) m = Monster() a = Alien() while True: x = input() if x=="laser" : print(a.hit()) elif x=="gun" : print(m.hit()) elif x == "exit": break

11th Jan 2023, 9:36 AM
Imran Shakil
Imran Shakil - avatar
1 Answer
+ 6
Just call a.hit() , m.hit() without print..
11th Jan 2023, 10:00 AM
Jayakrishna 🇼🇳