-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank.py
More file actions
46 lines (32 loc) · 956 Bytes
/
Copy pathbank.py
File metadata and controls
46 lines (32 loc) · 956 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Acct:
def __init__(self):
self._balance:int = 0
def __str__(self) :
return f"Your current account balance is: ${self._balance}"
def __add__(self,other):
if isinstance(other, Acct):
return f"${self._balance + other._balance}"
else:
raise TypeError("Both operands must be Acct instances")
# @property
# def balance(self):
# return self._balance
def deposit(self, n:int):
self._balance += n
def withdraw(self, n):
self._balance -= n
def transfer(self, other, n):
self._balance -= n
other._balance += n
def main():
account = Acct()
demo = Acct()
print(account)
account.deposit(180)
account.withdraw(60)
account.transfer(demo,70)
print(account)
print(f"In demo {demo}")
print("The total balance is",demo+account, sep=None)
if __name__ == "__main__":
main()