-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy path2043-simple-bank-system.py
More file actions
39 lines (31 loc) · 1.07 KB
/
2043-simple-bank-system.py
File metadata and controls
39 lines (31 loc) · 1.07 KB
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
from typing import List
class Bank:
def __init__(self, balance: List[int]):
self.balance = balance
self.n = len(balance)
def transfer(self, account1: int, account2: int, money: int) -> bool:
if account1 - 1 > self.n or account2 - 1 > self.n:
return False
if self.balance[account1 - 1] < money:
return False
self.balance[account1 - 1] -= money
self.balance[account2 - 1] += money
return True
def deposit(self, account: int, money: int) -> bool:
if account - 1 > self.n:
return False
self.balance[account - 1] += money
return True
def withdraw(self, account: int, money: int) -> bool:
if account - 1 > self.n:
return False
if self.balance[account - 1] < money:
return False
self.balance[account - 1] -= money
return True
bank = Bank([10, 100, 20, 50, 30])
print(bank.withdraw(3, 10))
print(bank.transfer(5, 1, 20))
print(bank.deposit(5, 20))
print(bank.transfer(3, 4, 15))
print(bank.withdraw(10, 50))