forked from fenyx-it-academy/Class7-Python-Module-Week4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek 4 - 1.py
More file actions
43 lines (30 loc) · 1020 Bytes
/
Week 4 - 1.py
File metadata and controls
43 lines (30 loc) · 1020 Bytes
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
########## School ###########
class School:
def __init__(self, capacity):
self.students = []
self.capacity = capacity
def add_student(self, *student):
if self.students == self.capacity:
print('No more spot for new studnets!')
else:
for stdnt in student:
self.students.append(stdnt)
def print_students(self):
for x in self.students:
print(x.__str__())
class Student(School):
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
def __str__(self):
return (f"{self.name} is {self.age} years old and he/she a {self.gender}.")
school = School(2)
student1 = Student('Safo', 27, 'male')
student2 = Student('Reco', 25, 'male')
student3 = Student('Melo', 27, 'female')
school.add_student(student1, student2)
school.print_students()
school.add_student(student3)
print(student1.__dict__)
print(school.__dict__)