-
Notifications
You must be signed in to change notification settings - Fork 0
/
bite11.py
70 lines (44 loc) · 1.35 KB
/
bite11.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class Account:
def __init__(self, name, start_balance=0):
self.name = name
self.start_balance = start_balance
self._transactions = []
@property
def balance(self):
return self.start_balance + sum(self._transactions)
def __len__(self):
return len(self._transactions)
def __str__(self):
return '{} account - balance: {}'.format(self.name, self.balance)
def __getitem__(self, i):
return self._transactions[i]
def __iter__(self):
for each in self._transactions:
yield each
def __add__(self, other):
if type(other) != int:
raise TypeError
self._transactions.append(other)
def __sub__(self, other):
if type(other) != int:
raise TypeError
self._transactions.append(-other)
def __eq__(self, other):
return self.balance == other.balance
def __lt__(self, other):
return self.balance < other.balance
def __gt__(self, other):
return self.balance > other.balance
def __le__(self, other):
return self.balance <= other.balance
def __ge__(self, other):
return self.balance >= other.balance
acc = Account('my_acc', 0)
acc + 1
acc + 2
acc - 2
acc1 = Account('master_card', 7)
print(acc.balance)
print(acc1.balance)
print(str(acc1))
print(acc < acc1)