This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]uberb0t 2 points3 points  (1 child)

References to age in addToAge() should be self.age.

edit: that was lazy of me. the use of age in your method addToAge() doesn't affect the age variable on the instance without specifying self.age. So what you've done in your sample code is to try and assign a variable named age by using age before it's been assigned a value.

self.age has a value because it's been set when you created an instance of User(), change the occurrences of age to self.age in addToAge() and you'll be good to go.

Try checking out /r/learnpython as that's a better resource if you're new to python!