Ex42 fill-in-the-blanks


question is i’m bit confused about the fill-in-the-blanks assignment given in ex42

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

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

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

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

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

## ?? Person is-a object
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 Person
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):

## ?? Salmon is-a Fish
class Salmon(Fish):

## ?? Hailbut is-a Fish
class Halibut(Fish):

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

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

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

## ?? 
mary.pet = satan

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

## ??
frank.pet = rover

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

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

## ?? harry is-a Hailbut
harry = Halibut()

as you can see i have fill most of them but not on the line 60 and 66
what i would wright is
on line 60: mary has-a pet Cat named Satan
on line 66: frank has-a pet Dog named Rover

is that right?
because i think that mary and frank both are having pet
and all other fill ups are right or not
i appreciate your explanation on the same


Hi @divyang_patel.

I will try to do the best I can on this one.

In the example mary has become an instance of the Person class.
I don’t know if one also can call mary an object (please correct me if I am wrong).
You can connect attributes to the object.
Like name in the Person class .

mary “got her name” like this.

mary = Person('Mary')

There is also a attribute called pet in the Person class.
In the class pet is set to None
Later it is set to ‘satan’ (which is also an instance of Cat)
But you can choose whatever you like (perhaps ‘Angel’ :slight_smile:)

mary.pet = 'Angel'

Perhaps ‘Mary’ want to have a car.
Add to the class the attribute: car.

self.car = None

Then give Mary the car :smiling_face_with_three_hearts:

mary.car = 'Tesla'

If you want to print it out type:

print(f"{mary.name} has a {mary.car} and a cat called {mary.pet}")
# the f-string is for Python 3.6 or higher.


Mary has a Tesla and a cat called Angel


thank you for your reply

as you said that mary is an instance ie the object of class Person and class Person has a attributes name and pet
pet is assign to None and we are passing value of name attribute Mary while creating instance of Person class which is mary
now here the thing that satan is an instance of Cat class and now value of attribute pet of an instance mary is set to satan
so what should happen
class Cat should run again and pass that name attribute of Cat class to an pet attribute an instance mary
i think it’s not
then what’s the point
why there is need to set an satan instance of Cat to an attribute pet of an instance mary
what is happening there, what is that line 61 doing and what you will right in fill up on line 60



I actually dont know. Zed has to answer that.

And I dont know if this works as intended.
When setting mary.pet = satan I got:

<main.Cat object at 0x108ceed68&gt>

If I want mary.pet = satan be equal to ”Satan”
I have set it to mary.pet = satan.name


i realized that i’m asking wrong question when you pointed out

i think i am just over thinking about setting satan to mary.pet
because the way zed said to find the relation between both so i think that Cat class will run again and there will be relation
but one thing that now mary.pet is also an object of Cat class, right?


Hi @divyang_patel

Yes. When you set mary.pet to satan.
Because satan is an instance of Cat.
That would be the relation.
You can check it with


mary.pet = ”Angel” would be a Person object because pet is a attribute of Person.
No other relations in here.


yes i did and it showing this

as you can see mary.pet is instance of Cat class

before you said to do

i did this


Hi @divyang_patel

I guess both of us have learned more from this.
At least I did. I hope you did too.


:grinning: yes
i rather not say that we learned something,
it’s something we seen that we don’t know
that’s weird :joy::joy::joy:
but we are still not sure what is happening, at least i am not


There is a saying i Sweden (perhaps elsewhere too) that the bumblebee doesn´t know it cannot fly.
So it flies around happily anyway.

Perhaps its the same with my coding in Python :sweat_smile:

Perhaps @zedshaw will put some comments in here about this.
That will tell if we are on the track or not.

Thanks for the conversation.


@ulfen69 thank you for sticking with me through strange time :grin:
i also think zed can show us something more on “strange” thing :sweat_smile:
have a great day :+1:


Just to clarify here @divyang_patel, but when you do this:

mary.pet = satan

Are you thinking that this creates a new Cat object? It actually just makes a link–aka a reference–to the original satan object. It doesn’t re-rerun Cat().


Thank you @zedshaw for clearing my doubt
yes earlier i was thinking that satan will run Cat but later i figured that there is no Class call, it’s just an object assignment