This repository was archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise-general-week-06-01.py
More file actions
78 lines (61 loc) · 2.06 KB
/
Copy pathexercise-general-week-06-01.py
File metadata and controls
78 lines (61 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from enum import Enum
from datetime import date, time, datetime
##---------------------------------------------------------------------------##
#
#
#
##---------------------------------------------------------------------------##
class Gender(Enum):
MALE = "M"
FEMALE = "F"
##---------------------------------------------------------------------------##
class Person:
name: str = None
last: str = None
gender: Gender = None
birth: date = None
def __init__(self, name: str, last: str, gender: Gender, birth: date) -> None:
self.name = name
self.last = last
self.gender = gender
self.birth = birth
def __str__(self) -> str:
return "({}) {} {} {}".format(
self.gender.value, self.name, self.last, self.birth
)
def __repr__(self) -> str:
return self.__str__()
##---------------------------------------------------------------------------##
# تمرین ۱
#
#
##---------------------------------------------------------------------------##
# تمرین ۲
#
#
##---------------------------------------------------------------------------##
# تمرین ۳
#
#
##---------------------------------------------------------------------------##
class People:
people = []
@classmethod
def add(cls, person: Person):
cls.people.append(person)
@classmethod
def filter(cls, year: int):
for person in cls.people:
if person.birth.year > year:
yield person
##---------------------------------------------------------------------------##
People.add(Person("Kate", "K", Gender.MALE, date(1941, 3, 11)))
People.add(Person("Roz", "R", Gender.FEMALE, date(1982, 2, 15)))
People.add(Person("Kevin", "K", Gender.MALE, date(1985, 9, 16)))
People.add(Person("David", "Hat", Gender.MALE, date(1990, 5, 12)))
People.add(Person("John", "JJ", Gender.FEMALE, date(1971, 11, 13)))
##---------------------------------------------------------------------------##
print(People.people)
print()
for person in People.filter(1950):
print(person)