Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oops concepts in python. Class . #82

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
47 changes: 47 additions & 0 deletions Oops concepts in python. Class .
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions README.md

This file was deleted.