Advertisement
HauntJemimah

Untitled

Apr 18th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1.  
  2. class Animal():
  3.     name = ""
  4.     def eat(self):
  5.         print("Munch munch.")
  6.     def makeNoise(self):
  7.         print("\"Grr,\" says", self.name, "\n")
  8.     def __init__(self):
  9.         print("An animal has been born.")
  10.  
  11. # http://programarcadegames.com/worksheets/show_file.php?file=worksheet_13.php
  12.  
  13. Panda = Animal()
  14. Panda.name = "Pandaman"
  15. Panda.eat()
  16. Panda.makeNoise()
  17.  
  18. # 2. Create a class named Cat:
  19.  
  20. # Make Animal the parent
  21.  
  22. # Make a makeNoise() method for Cat that prints "Meow says [animal name]."
  23.  
  24. # A constructor for Cat that prints "A cat has been born." and it calls the
  25. # parent constructor
  26.  
  27. class Cat(Animal):
  28.     def makeNoise(self):
  29.         print("\"Meow,\", says", self.name, "\n")
  30.     def __init__(self):
  31.         print("A cat has been born.")
  32.  
  33. MrButtons = Cat()
  34. MrButtons.makeNoise()
  35.  
  36. # Figure out how to print out the actual name from the Animal class
  37. # It probably involves indexing into the method using the dot operator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement