Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. class Enemy:
  2. life = 3
  3.  
  4. def attack(self):
  5. print('ouch!')
  6. self.life -= 1
  7.  
  8. def checkLife(self):
  9. if self.life <= 0:
  10. print('I am dead')
  11. else:
  12. print(str(self.life) + "life left")
  13.  
  14.  
  15. enemy1 = Enemy
  16. enemy1.attack()
  17. enemy1.checkLife()
  18.  
  19. C:UsersLiamAppDataLocalProgramsPythonPython36-32python.exe C:/Users/Liam/PycharmProjects/YouTube/first.py
  20. Traceback (most recent call last):
  21. File "C:/Users/Liam/PycharmProjects/YouTube/first.py", line 16, in <module>
  22. enemy1.attack()
  23. TypeError: attack() missing 1 required positional argument: 'self'
  24.  
  25. Process finished with exit code 1
  26.  
  27. enemy1 = Enemy()
  28. enemy1.attack()
  29. enemy1.checkLife()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement