fork download
  1. #create the "Enemy" class.
  2. class Enemy:
  3.  
  4. def _init_(self,name,color,hp,speed):
  5. self.name = name
  6. self.color = color
  7. self.hp = 100.00
  8. self.speed = 100.00
  9.  
  10. def summary(self):
  11. sum_str = "%s %s has %d hp and %d speed points." % (self.color, self.name, self.hp, self.speed)
  12. return sum_str
  13. #print ("EnemyName: ", self.name, ", Color: ", self.color, ", HP: ", self.hp, ", ", Speed: ", self.speed)
  14. #OR you can use the 'print' command directly...
  15.  
  16. # assign the class “Enemy” to the object “ene1” and “ene2” ,etc.,
  17. ene1 = Enemy()
  18. ene1.name = "Cheese"
  19. ene1.color = "Blue"
  20. ene1.hp = 50.00
  21. ene1.speed = 25.00
  22.  
  23. ene2 = Enemy()
  24. ene2.name = "Tomato"
  25. ene2.color = "Red"
  26. ene2.hp = 120.00
  27. ene2.speed = 35.00
  28.  
  29. ene3 = Enemy()
  30. ene3.name = "Garlic"
  31. ene3.color = "White"
  32. ene3.hp = 170.00
  33. ene3.speed = 40.00
  34.  
  35. ene4 = Enemy()
  36. ene4.name = "Egg"
  37. ene4.color = "Yellow"
  38. ene4.hp = 300.00
  39. ene4.speed = 60.00
  40.  
  41. # call the function
  42. print ene1.summary()
  43. print ene2.summary()
  44. print ene3.summary()
  45. print ene4.summary()
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
Blue Cheese has 50 hp and 25 speed points.
Red Tomato has 120 hp and 35 speed points.
White Garlic has 170 hp and 40 speed points.
Yellow Egg has 300 hp and 60 speed points.