Skip to content

Commit e98a571

Browse files
Boshra MahmoudiBoshra Mahmoudi
authored andcommitted
method exercise
1 parent a4b84ee commit e98a571

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎sprint5/Methods.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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) -> bool:
11+
today = date.today()
12+
13+
age = today.year - self.date_of_birth.year
14+
15+
if (today.month, today.day) < (
16+
self.date_of_birth.month,
17+
self.date_of_birth.day
18+
):
19+
age -= 1
20+
21+
return age >= 18
22+
23+
imran = Person(
24+
"Imran",
25+
date(2000, 5, 10),
26+
"Ubuntu"
27+
)
28+
29+
print(imran.is_adult())

0 commit comments

Comments
 (0)