-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathSimple Bank System.py
43 lines (39 loc) · 1.47 KB
/
Simple Bank System.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Runtime: 1834 ms (Top 5.30%) | Memory: 43.9 MB (Top 45.70%)
class Bank:
def __init__(self, bal: List[int]):
self.store = bal # storage list
def transfer(self, a1: int, a2: int, money: int) -> bool:
try:
# checking if both accounts exist. and if the transaction would be valid
if self.store[a1 - 1] >= money and self.store[a2 - 1] >= 0:
# performing the transaction
self.store[a1 - 1] -= money
self.store[a2 - 1] += money
return True
else:
# retrning false on invalid transaction
return False
except:
# returning false when accounts don't exist
return False
def deposit(self, ac: int, mn: int) -> bool:
try:
# if account exists performing transaction
self.store[ac - 1] += mn
return True
except:
# returning false when account doesn't exist
return False
def withdraw(self, ac: int, mn: int) -> bool:
try:
# checking if transaction is valid
if self.store[ac - 1] >= mn:
# performing the transaction
self.store[ac - 1] -= mn
return True
else:
# returning false in case on invalid transaction
return False
except:
# returning false when account doesn't exist
return False