From ed7b3ca8a5131883c73dd8bdb0e1e3a5695128b7 Mon Sep 17 00:00:00 2001 From: shatha6 Date: Mon, 17 Oct 2022 22:06:19 +0200 Subject: [PATCH] Week 4 Done OO --- BankAccount.py | 35 +++++++++++++++++++++++++++++++++++ Rectangle.py | 22 ++++++++++++++++++++++ School_Student.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 BankAccount.py create mode 100644 Rectangle.py create mode 100644 School_Student.py diff --git a/BankAccount.py b/BankAccount.py new file mode 100644 index 0000000..cbc26e3 --- /dev/null +++ b/BankAccount.py @@ -0,0 +1,35 @@ +# 3. BankAccount + + +class BankAccount: + def __init__(self,accountNumber,name,balance): + self.accountNumber = accountNumber + self.name = name + self.balance = balance + + def deposit(self,d): + self.balance = d+self.balance + return self.balance + + def withdrawal(self,w): + if w <= self.balance: + self.balance = self.balance-w + else: + print("Impossible operation! Insufficient balance!") + return self.balance + + def bankFees(self): + self.balance = self.balance - (self.balance*0.05) + return self.balance + + def desplay(self): + print(f"Bank Account Details:\nBank account number: {self.accountNumber}\nName: {self.name}\nBalance: {self.balance}") + +acc = BankAccount(1234,"shatha",150) +acc.deposit(50) +acc.withdrawal(10) +acc.withdrawal(50) +acc.withdrawal(40) +acc.bankFees() +acc.withdrawal(100) +acc.desplay() \ No newline at end of file diff --git a/Rectangle.py b/Rectangle.py new file mode 100644 index 0000000..a9c314e --- /dev/null +++ b/Rectangle.py @@ -0,0 +1,22 @@ +## 2. Rectangle + +class rectangle: + def __init__(self,lng,wd): + self.lng = lng + self.wd = wd + + def perimeter(self): + return 2*(self.lng+self.wd) + + def area (self): + return (self.lng*self.wd) + + def display(self): + print(f"Rectangle dimentions are {self.lng}, {self.wd}. Perimeter is {rectangle.perimeter(self)}. Area is {rectangle.area(self)}") + + + +rect = rectangle(5,10) +rect.perimeter() +rect.area() +rect.display() diff --git a/School_Student.py b/School_Student.py new file mode 100644 index 0000000..0a60a37 --- /dev/null +++ b/School_Student.py @@ -0,0 +1,43 @@ +## 1. School +class school: + s_lst = [] + s_count = 0 + def __init__(self,capacity): + self.capacity = capacity + + +class student: + def __init__(self,name,age,gender): + self.name = name + self.age = age + self.gender = gender + + def str (self): + return f"Student name: {self.name}\nStudent age: {self.age}\nStudent gender: {self.gender}" + + def add_student(self,capacity): + school.s_count = school.s_count +1 + print(school.s_count) + if school.s_count <= capacity: + school.s_lst.append(self) + else: + print("Sorry this student can't be added as the school capacity is full") + + + def print_student(self): + for i in school.s_lst: + print(i.name,i.age,i.gender) + + +scl = school(3) +stdnt1 = student("Shatha",22,"F") +stdnt2 = student("hata",21,"M") +stdnt3 = student("Ali",29,"M") +stdnt4 = student("Farah",30,"F") +stdnt1.add_student(scl.capacity) +stdnt2.add_student(scl.capacity) +stdnt3.add_student(scl.capacity) +stdnt4.add_student(scl.capacity) +stdnt1.print_student() +print(stdnt1.__dict__) +print(scl.__dict__) \ No newline at end of file