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
30 changes: 30 additions & 0 deletions 5.2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Rectangle:
def __init__(self, length , width):
self.length = length
self.width = width


def Perimeter(self):
return 2*(self.length + self.width)

def Area(self):
return self.length*self.width

def display(self):
print("The length of rectangle is: ", self.length)
print("The width of rectangle is: ", self.width)
print("The perimeter of rectangle is: ", self.Perimeter())
print("The area of rectangle is: ", self.Area())
class Parallelepipede(Rectangle):
def __init__(self, length, width , height):
Rectangle.__init__(self, length, width)
#super().__init__(length, width)
self.height = height

def volume(self):
return self.length*self.width*self.height

myRectangle = Rectangle(7 , 5)
myRectangle.display()
myParallelepipede = Parallelepipede(7 , 5 , 2)
print("the volume of myParallelepipede is: " , myParallelepipede.volume())
25 changes: 25 additions & 0 deletions 5.3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class BankAccount:
def __init__(self,accountNumber, name, balance):
self.accountNumber = accountNumber
self.name = name
self.balance = balance

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

def Withdrawal(self , w):
if(self.balance < w):
print("impossible operation! Insufficient balance !")
else:
self.balance = self.balance - w

def bankFees(self):
self.balance = (95/100)*self.balance

def display(self):
print("Account Number : " , self.accountNumber)
print("Account Name : " , self.name)
print("Account Balance : " , self.balance , " $")

newAccount = BankAccount(2178514584, "Albert" , 2700)
newAccount.display()
24 changes: 24 additions & 0 deletions 5.4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Person:
def __init__(self, name, age):
self.name = name
self.age = age

def display(self):
print("Person name : ", self.name)
print("Person age = ", self.age)

class Student(Person):
def __init__(self, name , age , section):
super().__init__(name, age)
self.section = section

def displayStudent(self):
print("Student name : ", self.name)
print("Student age = ", self.age)
print("Student section = ", self.section)

P = Person("Tomas Wild", 37)
P.display()

S = Student("Albert", 23 , "Mathematics")
S.displayStudent()
42 changes: 42 additions & 0 deletions school.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from unicodedata import name


class School:

students = []

def __init__(self, capacity):
self.capacity = capacity

def add_student(self, student):
if len(self.students) < self.capacity:
self.students.append(student)
else:
print('School capacity is full. Cannot register:', student)

def print_students(self):
print(f"There are {len(self.students)} students. With following info:")
for s in self.students:
print(s)

class Student:

def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender

def __str__(self):
return "Student with name {} and gender {}".format(self.name, self.age)

school = School(2)
student_1 = Student("Eva", 21, "female")
student_2 = Student("Jack", 18, "male")
student_3 = Student("Anna", 18, "female")
school.add_student(student_1)
school.add_student(student_2)
school.print_students()
school.add_student(student_3)

print(school.__dict__)
print(student_1.__dict__)