Skip to content

Commit 2fdc02c

Browse files
committed
using @datatype& datetime.date & add the is_adult method
1 parent 801b1c3 commit 2fdc02c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

sprint5-prep/prep5-exercise.py

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

0 commit comments

Comments
 (0)