0

Python Intermediate "Shooting Game" challenge answer

Please i need help on this challenge i have been stuck on it for a while and i need help or a answer preferably a answer.

22nd Feb 2021, 7:27 PM
Aiden Giuchin
Aiden Giuchin - avatar
4 Answers
+ 5
This worked for me :👇 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 == 'exit': break elif x == "laser": a.hit() else: m.hit()
23rd Feb 2021, 4:56 PM
Abhishek Mishra
Abhishek Mishra - avatar
+ 1
Share your attempt
22nd Feb 2021, 8:31 PM
Shivani 📚✍
Shivani 📚✍ - avatar
+ 1
class Enemy: name = "" lives = 0 def __init__(self, name, lives): self.name = name self.lives = lives def shooting(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) def shooting(self): super().shooting() class Alien(Enemy): def __init__(self): super().__init__('Alien', 5) def shooting(self): super().shooting() m = Monster() a = Alien() while True: x = input() if x == 'exit': break elif x == 'gun': m.shooting() elif x == 'laser': a.shooting()
25th Mar 2021, 12:09 AM
Adrian Salas Flores
Adrian Salas Flores - avatar
0
This worked for me :👇 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 == 'exit': break elif x == "laser": a.hit() else: m.hit()
17th Jun 2021, 4:27 AM
Vuppala Vishnu Hruthika