- 5

Python Shooting Game Intermediate level

You are creating a shooting game! The game has two types of enemies, aliens and monsters. You shoot the aliens using your laser, and monsters using your gun. Each hit decreases the lives of the enemies by 1. The given code declares a generic Enemy class, as well as the Alien and Monster classes, with their corresponding lives count. It also defines the hit() method for the Enemy class. You need to do the following to complete the program: 1. Inherit the Alien and Monster classes from the Enemy class. 2. Complete the while loop that continuously takes the weapon of choice from user input and call the corresponding object's hit() method. Please help The last code to do before getting my certificate. My code: 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: def __init__(self): super().__init__('Monster', 3) class Alien: def __init__(self): super().__init__('Alien', 5) m = Monster() a = Alien() while True: x = input() if x == 'exit': break Output: Traceback (most recent call last): File "/usercode/file0.py", line 24, in <module> m = Monster() File "/usercode/file0.py", line 17, in __init__ super().__init__('Monster', 3) TypeError: object.__init__() takes exactly one argument (the instance to initialize) Please tell the mistake.

14th May 2021, 10:34 AM
Mudit Kumar Singh
20 Answers
+ 3
this code gives an error, because you have not written a single line of your code. you just copied the task. you need to supplement it with these actions: You need to do the following to complete the program: 1. Inherit the Alien and Monster classes from the Enemy class. 2. Complete the while loop that continuously takes the weapon of choice from user input and call the corresponding object's hit() method.
15th May 2021, 5:49 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 24
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() elif x == 'gun': m.hit()
31st Jul 2021, 7:54 PM
David labadze
David labadze - avatar
+ 4
I just do some editing here 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 == "gun": m.hit() if x == "laser": a.hit() if x == 'exit': break
24th Jul 2021, 2:42 AM
Gusti Andika Pratama
+ 2
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() elif x == 'gun': m.hit()
9th Dec 2021, 3:05 PM
Mirmahmud Ilyosov
Mirmahmud Ilyosov - avatar
+ 1
Anyway, despite your attempts to write literally no code of your own, here's the solution: 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 == "gun": m.hit() if x == "laser": a.hit() if x == 'exit': break
24th Aug 2021, 5:13 PM
Kevin
+ 1
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() elif x == 'gun': m.hit()
16th Dec 2021, 6:19 AM
Marvin Manaog
Marvin Manaog - avatar
0
You literally have not posted any of your own code. I'm on the same exercise and that code you've posted is the exact code already given in the lesson. Why you would lie and pretend you wrote it is beyond me.
24th Aug 2021, 5:01 PM
Kevin
0
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() elif x == 'gun': m.hit()
16th Dec 2021, 6:16 AM
Marvin Manaog
Marvin Manaog - avatar
0
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() elif x == 'gun': m.hit() l
17th Dec 2021, 10:19 AM
Ismoilov Abdug'ofur
Ismoilov Abdug'ofur - avatar
0
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() elif x == 'gun': m.hit()
20th Dec 2021, 7:05 AM
Md. Rakibul Islam
Md. Rakibul Islam - avatar
0
:>>>>>>>
13th Jan 2022, 8:18 PM
Thuwayba Ahmed
Thuwayba Ahmed - avatar
0
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() elif x == 'gun': m.hit()
31st Mar 2022, 11:19 PM
Abdelkhalek Nael Ahmad Allan
Abdelkhalek Nael Ahmad Allan - avatar
0
some tiny changes I did , instead I had put a return statement def hit(self): self.lives -= 1 if self.lives <= 0: return (self.name + ' killed') else: return (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()) if x == 'gun' : print (m.hit()) if x == 'exit': break
10th Aug 2022, 9:27 AM
anas safi
0
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 == 'gun': m.hit() elif x == 'laser': a.hit()
15th Nov 2022, 8:19 PM
Guy Martial KEYOU
- 1
I have given my code. Now please tell the mistake.
15th May 2021, 4:15 AM
Mudit Kumar Singh
- 1
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() elif x == 'gun': m.hit()
15th Aug 2021, 6:06 PM
Vraj Soni
Vraj Soni - avatar
- 1
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() elif x == 'gun': m.hit()
11th Sep 2021, 6:02 PM
Budhabhushan Waghmare
Budhabhushan Waghmare - avatar
- 1
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() elif x == 'gun': m.hit()
1st Oct 2021, 3:56 PM
Hariom Kumar
Hariom Kumar - avatar
- 1
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): #Inherit Monster classes from the Enemy class. def __init__(self): super().__init__('Monster', 3) class Alien(Enemy): #Inherit Alien classes from the Enemy class. def __init__(self): super().__init__('Alien', 5) m = Monster() a = Alien() while True: x = input() if x == 'exit': break elif x == 'laser': #corresponding object's hit() method. a.hit() elif x == 'gun': m.hit()
13th Oct 2021, 4:49 AM
Pratap Vasava
Pratap Vasava - avatar
- 2
Hi! Please, for better help, show us your code attempt! Thx! Edit: We look forward to your efforts with great hope
14th May 2021, 10:41 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar