Skip to content

Commit d7d72c1

Browse files
committed
exercise 7 completed
1 parent d441881 commit d7d72c1

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from datetime import date
2+
3+
class Person:
4+
def __init__(self, name: str, age: int, preferred_operating_system: str, dob: date):
5+
self.name = name
6+
self.age = age
7+
self.preferred_operating_system = preferred_operating_system
8+
self.dob = dob
9+
10+
def is_adult(self):
11+
dob = self.dob
12+
today = date.today()
13+
if dob.year > today.year - 18: return False
14+
if dob.year == today.year - 18:
15+
if dob.month > today.month: return False
16+
if dob.month == today.month:
17+
if dob.day > today.day: return False
18+
return True
19+
20+
21+
imran = Person("Imran", 22, "Ubuntu", date(2004, 8, 31))
22+
print(imran.is_adult())
23+
24+
# Change the Person class to take a date of birth
25+
# (using the standard library’s datetime.date class) and store it in a field instead of age.
26+
27+
# Update the is_adult method to act the same as before.

0 commit comments

Comments
 (0)