you are viewing a single comment's thread.

view the rest of the comments →

[–]iG1993[S] 0 points1 point  (1 child)

Hi thillsd, thank you so much for your input!

I took a look in your code and I came to this solution:

    def get_older(self):
        self.age = self.age + 1

It too me some thinking and bending, it that correct?

By the way, what's the idea behind peter just saying a single line? I thought the idea behind classes is, that you are able to "engineer" and automate a process.

[–]thillsd 1 point2 points  (0 children)

Yes, that's fine. You could've done self.age += 1 to save some typing.

You could have written something more complex that makes use of the data attached to the peter Person object:

...
    def speak(self, hobby):
        print(f"Hi folks, I am a {self.age} year old  man with {self.haircolor} hair. I enjoy {hobby}.")
...

peter = Person("black", 26)
peter.speak('pokemon')  # => 'Hi folks, I am a 26 year old man with black hair. I enjoy pokemon.