Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions first_answer.py
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions second_answer.py
Original file line number Diff line number Diff line change
@@ -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())
33 changes: 33 additions & 0 deletions third_answer.py
Original file line number Diff line number Diff line change
@@ -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()