File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from datetime import date
2+
3+
4+ class Person :
5+
6+ def __init__ (self , name : str , date_of_birth : date ):
7+ self .name = name
8+ self .date_of_birth = date_of_birth
9+
10+ def is_adult (self ) -> bool :
11+ current_date = date .today ()
12+ full_years = current_date .year - self .date_of_birth .year
13+ if (current_date .month < self .date_of_birth .month ) or (
14+ current_date .month == self .date_of_birth .month
15+ and current_date .day < self .date_of_birth .day
16+ ):
17+ full_years -= 1
18+ return full_years >= 18
19+
20+
21+ imran = Person ("Imran" , date (2008 , 1 , 30 ))
22+ eliza = Person ("Eliza" , date (2088 , 7 , 30 ))
23+ someone = Person ("Someone" , date (2021 , 7 , 30 ))
24+ print ("Imran is adult: " + str (imran .is_adult ()))
25+ print ("Eliza is adult: " + str (eliza .is_adult ()))
26+ print ("Someone is adult: " + str (someone .is_adult ()))
You can’t perform that action at this time.
0 commit comments