From 54eacea008bf167ffc2ee3f7e9f31f4d2e9f3905 Mon Sep 17 00:00:00 2001 From: Akash-200444 Date: Sun, 13 Oct 2024 12:25:04 +0530 Subject: [PATCH] Update and rename README.md to Oops concepts in python. Class . --- Oops concepts in python. Class . | 47 ++++++++++++++++++++++++++++++ README.md | 3 -- 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 Oops concepts in python. Class . delete mode 100644 README.md diff --git a/Oops concepts in python. Class . b/Oops concepts in python. Class . new file mode 100644 index 0000000..6d5077c --- /dev/null +++ b/Oops concepts in python. Class . @@ -0,0 +1,47 @@ +# Base class: BankAccount +class BankAccount: + def __init__(self, account_number, owner, balance=0): + self.account_number = account_number + self.owner = owner + self.balance = balance + + def deposit(self, amount): + if amount > 0: + self.balance += amount + print(f"Deposited {amount}. New balance: {self.balance}") + else: + print("Deposit amount must be positive.") + + def withdraw(self, amount): + if amount > 0 and amount <= self.balance: + self.balance -= amount + print(f"Withdrew {amount}. New balance: {self.balance}") + else: + print("Insufficient balance or invalid withdrawal amount.") + + def display_balance(self): + print(f"Account Number: {self.account_number} | Owner: {self.owner} | Balance: {self.balance}") + +# Derived class: SavingsAccount +class SavingsAccount(BankAccount): + def __init__(self, account_number, owner, balance=0, interest_rate=0.01): + super().__init__(account_number, owner, balance) + self.interest_rate = interest_rate + + def apply_interest(self): + interest = self.balance * self.interest_rate + self.balance += interest + print(f"Interest of {interest} applied. New balance: {self.balance}") + +# Derived class: CheckingAccount +class CheckingAccount(BankAccount): + def __init__(self, account_number, owner, balance=0, overdraft_limit=500): + super().__init__(account_number, owner, balance) + self.overdraft_limit = overdraft_limit + + def withdraw(self, amount): + if amount > 0 and (self.balance + self.overdraft_limit) >= amount: + self.balance -= amount + print(f"Withdrew {amount}. New balance: {self.balance}") + else: + print("Withdrawal exceeds overdraft limit diff --git a/README.md b/README.md deleted file mode 100644 index 6e53c4c..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# FlutterClass - -More details : https://github.com/ViluppuramGLUG/FlutterClass/tree/main/vglug