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
43 changes: 43 additions & 0 deletions Week 4 - 1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
########## 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__)




19 changes: 19 additions & 0 deletions Week 4 - 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
##################### Rectangle ########################


class Rectangle:
def __init__(self, lenght, width):
self.lenght = lenght
self.width = width

def perimeter(self):
return 2*(self.lenght + self.width)

def area(self):
return(self.lenght * self.width)

def display(self):
return(f'{self.lenght} {self.width} {self.perimeter()} {self.area()}')

result = Rectangle(8, 9)
print(result.display())
37 changes: 37 additions & 0 deletions Week 4 - 3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
####################### Bank Account ########################

class BankAccount:
def __init__(self, accountNumber, name, balance):

self.accountNumber = accountNumber
self.name = name
self.balance = balance

def deposit(self, d):
self.balance += d

def withdrawal(self, w):
if self.balance > w:
print('Impossible operation! Insufficient balance!')
else:
self.balance -= w


def bankFees(self):
self.balance = 1.05 * self.balance

def display(self):
print(f'''
Account Number {self.accountNumber}
Name {self.name}
Balance {self.balance}
''')

x = BankAccount(123456789, 'Saffet', 1000)
x.withdrawal(200)
x.deposit(5000)
x.display()