Skip to content

Commit 17533e8

Browse files
committed
complete method exercise
1 parent 9937825 commit 17533e8

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎sprint5-prep-exercises/methods.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from datetime import date
2+
3+
4+
class Person:
5+
def __init__(self, name: str, date_of_birth: date, preferred_operating_system: str):
6+
self.name = name
7+
self.date_of_birth = date_of_birth
8+
self.preferred_operating_system = preferred_operating_system
9+
10+
def is_adult(self):
11+
today = date.today()
12+
age = today.year - self.date_of_birth.year
13+
14+
if (today.month, today.day) < (
15+
self.date_of_birth.month,
16+
self.date_of_birth.day,
17+
):
18+
age -= 1
19+
20+
return age >= 18
21+
22+
23+
imran = Person("Imran", date(2000, 2, 10), "Ubuntu")
24+
print(imran.is_adult())

0 commit comments

Comments
 (0)