-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2043_Simple_Bank_System.py
More file actions
34 lines (25 loc) · 1.06 KB
/
2043_Simple_Bank_System.py
File metadata and controls
34 lines (25 loc) · 1.06 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
class Bank:
def __init__(self, balance: list[int]):
self.balance = [0] + balance
def transfer(self, account1: int, account2: int, money: int) -> bool:
if account1 > len(self.balance) - 1 or account2 > len(self.balance) - 1 or self.balance[account1] < money:
return False
self.balance[account1] -= money
self.balance[account2] += money
return True
def deposit(self, account: int, money: int) -> bool:
if account > len(self.balance) - 1:
return False
self.balance[account] += money
return True
def withdraw(self, account: int, money: int) -> bool:
if account > len(self.balance) - 1 or self.balance[account] < money:
return False
self.balance[account] -= money
return True
bank = Bank([10, 100, 20, 50, 30])
print(bank.withdraw(3, 10)) # True
print(bank.transfer(5, 1, 20)) # True
print(bank.deposit(5, 20)) # True
print(bank.transfer(3, 4, 15)) # False
print(bank.withdraw(10, 50)) # False