Skip to content

Commit aaf5689

Browse files
Boshra MahmoudiBoshra Mahmoudi
authored andcommitted
dataclasses exercise
1 parent e98a571 commit aaf5689

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎sprint5/dataclasses-example.py‎

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

0 commit comments

Comments
 (0)