Python Intermediate "Shooting Game" challenge answer | Sololearn: Learn to code for FREE!

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.

2/22/2021 7:27:45 PM

Aiden Giuchin

4 Answers

New Answer

+4

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()

+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()

0

Share your attempt

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()