Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6244643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:21:42+00:00 2026-05-24T12:21:42+00:00

I’m going through Learn Python the Hard Way 2nd Edition and I’ve just done

  • 0

I’m going through Learn Python the Hard Way 2nd Edition and I’ve just done the exercise where am suppose to write down the is-a/has-a relationships. Am able to use classes somehow but i find is-a/has-a confusing. So I have no ideas if what I’ve done is correct, any pointers will be appreciated. Thanks.

## Animal is-a object (yes, sort of confusing) look at the extra credit
class Animal(object):
    pass


## ?? Dog is-a object
class Dog(Animal):

    def __init__(self, name):
        ## ?? Dog has-a name
        self.name = name

## ?? Cat is-a object
class Cat(Animal):

    def __init__(self, name):
        ## ?? Cat has-a name
        self.name = name

class Person(object):

    def __init__(self, name):
        ## ?? Person has-a name
        self.name = name

        ## Person has-a pet of some kind
        self.pet = None

## ?? Employee is-a object
class Employee(Person):

    def __init__(self, name, salary):
        ## ?? hmm  what is this strange magic? 
        super(Employee, self).__init__(name)
        ## ?? Employee has-a salary
        self.salary = salary

## ?? Fish is-a object
class Fish(object):
    pass

## ?? Salmon is-a object, type of a fish
class Salmon(Fish):
    pass

## ?? Halibut is-a object, type of a fish
class Halibut(Fish):
    pass

## rover is-a Dog
rover = Dog("Rover")

## ?? satan is-a Cat
satan = Cat("Satan")

## ?? mary is-a person
mary = Person("Mary")

## ?? mary has-a pet called satan
mary.pet = satan

## ?? frank is-a Employee on 120000 salary
frank = Employee("Frank", 120000)

## ?? frank has-a pet called rover
frank.pet = rover

## ?? flipper is Fish
flipper = Fish()

## ?? crouse is-a Salmon
crouse = Salmon()

## ?? harry is-a Halibut
harry = Halibut()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:21:43+00:00Added an answer on May 24, 2026 at 12:21 pm

    So you are close. I remember struggling with the OOP paradigm at first also, especially after learning some c. Anyway, OOP is really more common sense than it may seem… The only tricky bit here is the first one, which was given to you… Animal is an Object.

    While you are correct that Dogs, Cats, and Employees are objects, they are more importantly Animals, Animals, and People respectively.

    This exercise is really about a property of OOP, inheritance. For instance, the class hierarchy for Dog:

    Object -> Animal -> Dog

    A dog is both an Animal and an Object, and it ‘has’ all of the properties of both. Now the properties can be overridden in subclasses, but that’s for later discussion.

    I think you started to get this around the Halibut and Salmon section. They are both Objects and Fish.

    The last bit I would say, is:

    Frank is an Employee (and Person and Object) whose name is Frank and has a salary of 120000.

    I hope that helped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.