Guest User

Untitled

a guest
Nov 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. """
  2. Object Oriented Programming (Thanksgiving Giving style)
  3.  
  4. We start defining classes with Animals.
  5. We can define that parent of the class, Animals, as well as the parent of that class.
  6.  
  7. However, to save time we start at Animals. Starting here; instead of
  8. directly at the turkey class, should help keep in mind we can define everything
  9. under the sun using OOP is we wanted to. Again, we will save time!
  10. """
  11.  
  12. class Animals():
  13. pass
  14.  
  15. class Turkey(Animals):
  16. """Attempt to model a turkey."""
  17.  
  18. # Create an instance based on the class Turkey.
  19. # This instance will have three parameters: self, name, age
  20.  
  21. def __init__(self, name, age):
  22. """Initialize name age and age attributes."""
  23. # Make accessible attributes or variables:
  24. self.name = name
  25. self.age = age
  26.  
  27. # Tell Python what a turkey can do by
  28. # defining the methods of the class
  29.  
  30. # Gobble Method
  31. def gobble(self):
  32. """Simulate a turkey gobbling in response to something."""
  33. print(self.name.title() + " is now gobbling!")
  34.  
  35. # More methods can follow here
  36.  
  37.  
  38. # Make an instance representing a specific turkey
  39.  
  40. my_turkey = Turkey('scrappy', 3)
  41. print("My turkey's name is " + my_turkey.name.title() + ".")
  42. print("My turkey is " +str(my_turkey.age) + " years old.")
  43.  
  44. # Calling methods
  45. my_turkey.gobble()
  46.  
  47. # Make multiple instances
  48. your_turkey = Turkey('lassy', 1)
Add Comment
Please, Sign In to add comment