Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal():
- name = ""
- def eat(self):
- print("Munch munch.")
- def makeNoise(self):
- print("\"Grr,\" says", self.name, "\n")
- def __init__(self):
- print("An animal has been born.")
- # http://programarcadegames.com/worksheets/show_file.php?file=worksheet_13.php
- Panda = Animal()
- Panda.name = "Pandaman"
- Panda.eat()
- Panda.makeNoise()
- # 2. Create a class named Cat:
- # Make Animal the parent
- # Make a makeNoise() method for Cat that prints "Meow says [animal name]."
- # A constructor for Cat that prints "A cat has been born." and it calls the
- # parent constructor
- class Cat(Animal):
- def makeNoise(self):
- print("\"Meow,\", says", self.name, "\n")
- def __init__(self):
- print("A cat has been born.")
- MrButtons = Cat()
- MrButtons.makeNoise()
- # Figure out how to print out the actual name from the Animal class
- # It probably involves indexing into the method using the dot operator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement