Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Breeds of dogs with constructors

Code listing

class Dog:

  def __init__(self):
    self.height = 4

  def bark(self):
    print "woof"

  def wag(self):
    print "wag wag wag"

class Dachshund(Dog):

  def __init__(self):
    self.height = 1

  def dig(self):
    print "dig dig dig"

  def bark(self):
    print "arf arf"

class Collie(Dog):
  def rescue(self, person):
    print "Come quickly, " + person + " fell down the mineshaft"

Command area transcript

>>> lassie = Collie()
>>> lassie.height
4
>>> pickles = Dachshund()
>>> pickles.height
1
>>> lassie.bark()
woof
>>> pickles.bark()
arf arf
>>> pickles.dig()
dig dig dig
>>> lassie.dig()
The error was:dig
Attribute not found.
You are trying to access a part of the object that doesn't exist.
AttributeError: dig
>>> 


Link to this Page