forked from ashishps1/awesome-low-level-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount.py
More file actions
23 lines (19 loc) · 701 Bytes
/
Copy pathaccount.py
File metadata and controls
23 lines (19 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from decimal import Decimal
from exception import InsufficientFundsException
class Account:
def __init__(self, id, user, account_number, currency):
self.id = id
self.user = user
self.account_number = account_number
self.currency = currency
self.balance = Decimal('0.00')
self.transactions = []
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
if self.balance >= amount:
self.balance -= amount
else:
raise InsufficientFundsException("Insufficient funds in the account.")
def add_transaction(self, transaction):
self.transactions.append(transaction)