diff --git a/first_answer.py b/first_answer.py new file mode 100644 index 0000000..ee454a4 --- /dev/null +++ b/first_answer.py @@ -0,0 +1,45 @@ +class School: + students = [] + + def __init__(self, capacity: int): + self.capacity = capacity + + +class Student(School): + num_of_students = 0 + + def __init__(self, name, age, gender): + self.name = name + self.age = age + self.gender = gender + Student.num_of_students += 1 + + def __str__(self): + return f'''' + studen name = {self.name} + age = {self.age} + gender = {self.gender} + ''' + + def add_student(self, capacity): + if Student.num_of_students <= capacity: + School.students.append(self) + else: + print("OOps!, it is full capacity") + + def print_students(self): + for i in School.students: + print(Student.__str__(self)) + + +cap = School(2) +student1 = Student("Mike", 20, "M") +student2 = Student("Jack", 22, "M") + +student1.add_student(cap.capacity) +student2.add_student(cap.capacity) +print(cap.students) + +student3 = Student("Lily", 21, "F") +student3.add_student(cap.capacity) +print(cap.students) diff --git a/second_answer.py b/second_answer.py new file mode 100644 index 0000000..c533c35 --- /dev/null +++ b/second_answer.py @@ -0,0 +1,23 @@ +class Rectangle: + + def __init__ (self, length, width): + self.length = length + self.width = width + + def perimeter(self): + return 2 * (self.width + self.length) + + def area(self): + return self.width * self.width + + def display(self): + return f'''' + Length = {self.length} + Width = {self.width} + Perimeter = {self.perimeter()} + area = {self.area()} + ''' + + +r = Rectangle(5,6) +print(r.display()) diff --git a/third_answer.py b/third_answer.py new file mode 100644 index 0000000..062ee32 --- /dev/null +++ b/third_answer.py @@ -0,0 +1,33 @@ +class BankAccount: + fee = 0.05 + + def __init__(self, accountNumber, name, balance): + self.accountNumber = accountNumber + self.name = name + self.balance = balance + + def deposit(self, d): + self.balance += d + + def withdraw(self, w): + if w <= self.balance: + self.balance -= w + else: + print("Impossible operation! Insufficient balance!") + + def bankFees(self): + self.balance -= (BankAccount.fee * self.balance) + + def display(self): + print(f'''' + Account Number = {self.accountNumber} + Name = {self.name} + Balance = {self.balance} + ''') + + +r1 = BankAccount(56445, "ghassan", 2000) +r1.display() +r1.deposit(1000) +r1.withdraw(500) +r1.display()