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+ import datetime as dt # we import the datetime module
2+
3+ # this is similar to new Date() object in js, but only getting the date not hours etc.
4+
5+ class Person :
6+ def __init__ (self , name : str , preferred_os : str , dob : dt .date ):
7+ self .name = name
8+ self .preferred_operating_system = preferred_os
9+ self .date_of_birth = dob
10+
11+ def is_adult (self ) -> bool :
12+ today = dt .date .today ()
13+ age = today .year - self .date_of_birth .year
14+ if (today .month , today .day ) < (self .date_of_birth .month , self .date_of_birth .day ):
15+ # if the birthday date did not happened yet ad -1 else skip it, we use full age
16+ age -= 1
17+ return age >= 18
18+
19+ imran_dob = dt .date (1986 , 12 , 24 )
20+ imran = Person ("Imran" , "Ubuntu" , imran_dob )
21+
22+ print (f"{ imran .name } is adult: { imran .is_adult ()} " )
You can’t perform that action at this time.
0 commit comments