Python :20.Classes-6:Referring number variables


Good Morning Friends, I am stuck at

My code gives following error message

Oops, try again. my_car does not have a color member variable.

class Car(object):
    def __init__(self,model,colour,mpg):

print my_car.condition
print my_car.model
print my_car.colour
print my_car.mpg


Misspelling there..

Its color (USA version) not colour (UK version)

Take a look at your code again!


Thanks for prompt reply,I made spelling corrections ,still get following error

Oops, try again. The color of my_car should be "silver".


Did you corrected all of them ?


Also eliminate the commas!
Python relies on indentation rather than commas!


Isn't it unnecessary to connect in inherited classes?


Did the issue solved?


Yes ,I finally solved it.Following is my code


Isn't it unnecessary to connect in inherited classes?

Inheritance makes OOP a powerful concept.
There are so many problems of same nature. by use of inheritance, you will able to solve them efficiently. (I know it may look like an alien thing to say if you're completely new to oop)

Tho I will help you to understand basic difference between Class, Instance and Object. (because you will see it is being used a lot in Python OOP section)
This answer I got from , I hope it will clear your concepts!

Lets say you want to create a horrifying boogeyman. So, you take a pen and a paper and start noting down what will your boogeyman look like.
-­ Long hairs
­ -Sharp teeth
­ - Red Body
-­ Swollen eyes
And what your boogeyman does ­
­- Attacks and kills people when he sees them
­ - Eats brain
­- Sleeps with noise
­- Draws blood from the neck
- So, your boogeyman is ready to be manufactured based on the above guidelines.
Now, you give these details to Boogeymaker, who can make you your own real life boogeyman. Although if you ask him how does he manufacture one, he may not tell
Lets say you want 4 of them. After a few hours the boogeymaker comes back and gives you your own 4 boogeymen with which, it is time you go scaring away others.
But, hey, here is a problem. All boogeymen are identical, thanks to the accurate guidelines. How do I ask one boogyman to attack and the other to eat brain? Well,
simple I name them say ­ boogey1, boogey2, boogey3, boogey4

Guidelines/Template that your created for the boogeyman is your class.
The 4 boogeymen supplied by the boogeymaker is your objects
The 4 names that you assigned to your boogey army is your instances

(Thanks to original poster of this Answer)
Back to inheritance:

You can delete your solution(by editing)

note don't share your final working code as other fellow learners can copy ,paste and use it.


You can delete your answer (others will just copy-paste it)! (edit it)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.