Python :20.Classes-6:Referring number variables


#1

Good Morning Friends, I am stuck at https://www.codecademy.com/en/courses/python-intermediate-en-egNXj/0/6?curriculum_id=4f89dab3d788890003000096

My code gives following error message

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


class Car(object):
    condition="new"
    def __init__(self,model,colour,mpg):
        self.model=model,
        self.colour=colour,
        self.mpg=mpg

my_car=Car("DeLorean","silver",88)
    
    
print my_car.condition
print my_car.model
print my_car.colour
print my_car.mpg


#2

Misspelling there..

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

Take a look at your code again!


#3

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

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

#4

Did you corrected all of them ?


#5

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


#6

Isn't it unnecessary to connect in inherited classes?


#7

Did the issue solved?


#8

Yes ,I finally solved it.Following is my code


#9

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 www.quora.com , 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
you.
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:
https://www.programiz.com/python-programming/inheritance

update**
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.


#10

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


#11

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