Skip to content

Commit 550d3a4

Browse files
committed
methods.py
1 parent e8b987d commit 550d3a4

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

sprint5-prep-exercises/methods.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from datetime import date
2+
3+
4+
class Person:
5+
6+
def __init__(self, name: str, date_of_birth: date):
7+
self.name = name
8+
self.date_of_birth = date_of_birth
9+
10+
def is_adult(self) -> bool:
11+
current_date = date.today()
12+
full_years = current_date.year - self.date_of_birth.year
13+
if (current_date.month < self.date_of_birth.month) or (
14+
current_date.month == self.date_of_birth.month
15+
and current_date.day < self.date_of_birth.day
16+
):
17+
full_years -= 1
18+
return full_years >= 18
19+
20+
21+
imran = Person("Imran", date(2008, 1, 30))
22+
eliza = Person("Eliza", date(2088, 7, 30))
23+
someone = Person("Someone", date(2021, 7, 30))
24+
print("Imran is adult: " + str(imran.is_adult()))
25+
print("Eliza is adult: " + str(eliza.is_adult()))
26+
print("Someone is adult: " + str(someone.is_adult()))

0 commit comments

Comments
 (0)