We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
In all of your class methods, such as amIOld and yearPasses, you need to use self.age to get the same variable as in your __init__. Your use of global means it's not referencing the variable initialized as part of the instance in your __init__ and will lead to bugs, even if it's passing these naive test cases. (In general, always always always stay away from global or else you will get bitten). To properly solve this, just change all instances of age to self.age and your answer will be pretty much identical to mine.
Day 4: Class vs. Instance
You are viewing a single comment's thread. Return to all comments →
In all of your class methods, such as
amIOld
andyearPasses
, you need to useself.age
to get the same variable as in your__init__
. Your use of global means it's not referencing the variable initialized as part of the instance in your__init__
and will lead to bugs, even if it's passing these naive test cases. (In general, always always always stay away fromglobal
or else you will get bitten). To properly solve this, just change all instances ofage
toself.age
and your answer will be pretty much identical to mine.