Skip to content

Commit 2e77268

Browse files
author
Fatma Degirmenci
committed
Refactor Person class
1 parent 79d0a12 commit 2e77268

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

sprint5/data_classes.py

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

0 commit comments

Comments
 (0)