-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank Account System.py
More file actions
25 lines (22 loc) · 942 Bytes
/
Copy pathBank Account System.py
File metadata and controls
25 lines (22 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class BankAccount:
_next_account_number = 1000
def __init__(self, account_holder, initial_balance=0):
self.account_holder=account_holder
self.balance=initial_balance
self.account_number=BankAccount._next_account_number
BankAccount._next_account_number += 1
def deposit(self,amount):
if amount<=0:
raise ValueError("Deposit amount must be positive.")
self.balance+=amount
def withdraw(self,amount):
if amount<=0:
raise ValueError("Withdraw Money should be positive")
if amount>self.balance:
raise ValueError("Insufficient Funds")
self.balance-=amount
def transfer(self,other_account_holder,amount):
if not isinstance(other_account_holder,BankAccount):
raise TypeError("Account Doesnt exists")
self.withdraw(amount)
other_account_holder.deposit(amount)