We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4e2e07e commit 77ca2f6Copy full SHA for 77ca2f6
1 file changed
Sprint5/methods.py
@@ -0,0 +1,24 @@
1
+from datetime import date
2
+class Person:
3
+ def __init__(self, name: str, birth_day: date):
4
+ self.name = name
5
+ self.birth_day = birth_day
6
+
7
+ def age(self)-> int: #returns age in years
8
+ today = date.today()
9
+ years = today.year - self.birth_day.year
10
+ if(today.month, today.day) < (self.birth_day.month, self.birth_day.day):
11
+ years -= 1
12
+ return years
13
14
+ def is_adult(self):
15
+ return self.age() >= 18
16
17
+ def __str__(self) -> str:
18
+ return f"{self.name}, born {self.birth_day}, age {self.age()}"
19
20
+p1 = Person("Sara", date(1996, 10, 28))
21
+print(p1.is_adult()) # True
22
23
+p2 = Person("Muhib", date(2018, 6, 22))
24
+print(p2.is_adult()) # False
0 commit comments