London | 26-SDC-MAR | Craig D'Silva | Sprint 5 | Prep#496
Conversation
LonMcGregor
left a comment
There was a problem hiding this comment.
Good work, can you review my 2 comments please
| self.preferred_operating_system = preferred_operating_system | ||
|
|
||
| def is_adult(self): | ||
| return self.age >= 18 |
There was a problem hiding this comment.
Can you think of any conditions where this approach of pre-calculating the age in the constructor might cause problems?
| class Person: | ||
| name: str | ||
| age: dt.date | ||
| preferred_operating_system: str |
There was a problem hiding this comment.
Can you add the is_adult method here and test that it still works?
There was a problem hiding this comment.
In this exercise, we need to add the date of birth instead of age. In order to check if the person is an adult, I would need to create another method which calculates the date of birth with today's date and return a boolean if the person is an adult.
LonMcGregor
left a comment
There was a problem hiding this comment.
While calculating the age at class instantiation time is not a wrong approach, if this were part of a long-lived application, it's possible that enough time could pass that what is stored in age would be out of date with how things actually are. I'm also not sure if this accurately captures the full age, as it only looks at whole years and not partial years.
Could you combine this with your suggestion for the other task, and try to build a method that can figure out whether they are an adult, using the dob, and whatever the current date is when the method is called?
Learners, PR Template
Self checklist
Changelist
This is the prep work for week 5.