Skip to content

Commit c172120

Browse files
committed
I used dataclass to help shortened my code and define the type of the object
1 parent d7b5b7a commit c172120

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

751 Bytes
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from dataclasses import dataclass
2+
from datetime import date
3+
4+
@dataclass(frozen=True)
5+
class Person:
6+
name: str
7+
date_of_birth: str
8+
preferred_operating_system: str
9+
10+
def is_adult(self):
11+
today_date = date.today()
12+
birth_date = date.fromisoformat(self.date_of_birth)
13+
age = today_date.year - birth_date.year
14+
15+
return age >= 18
16+
17+
18+
imran = Person("Imran", "2019-10-18", "Ubuntu")
19+
20+
print(imran.is_adult())

0 commit comments

Comments
 (0)