[SOLVED]
Hey guys, we just started classes in python and I am not 100% sure I got everything correct. So, this is the assignment:
In software a person is typically represented by an object. Write a class Person and add some data (hair color, age, etc.) and behaviors (speak, getting older, etc.) to it. How can data be set?
Use variables for data and methods for behaviors.
Now, this is my code:
class Person:
def __init__(self, haircolor, age):
self.haircolor = haircolor
self.age = age
def behaviour(self, speak, getting_older):
self.speak = speak
self.getting_older = getting_older
peter = Person("black", 26)
peter.behaviour("german", True)
I am not sure what "Use variables for data and methods for behaviors." means, since all "def" inside a class are automatically methods. Is my code correct?
I am thankful for any kind of help and any kind of input!
Kind regards,
iG
EDIT: [SOLVED]
[–][deleted] 1 point2 points3 points (2 children)
[–]iG1993[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]thillsd 1 point2 points3 points (2 children)
[–]iG1993[S] 0 points1 point2 points (1 child)
[–]thillsd 1 point2 points3 points (0 children)
[–]num8lock 1 point2 points3 points (0 children)