-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path066.BankAccount.py
65 lines (53 loc) · 1.9 KB
/
066.BankAccount.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
import datetime
import pytz
class Account:
""" Simple Account class with Balance """
@staticmethod
def _current_time():
utc_time = datetime.datetime.utcnow()
return pytz.utc.localize(utc_time)
def __init__(self, name, balance):
self._name = name
self.__balance = balance
self._transaction_list = []
print("Account Created for " + self._name)
self._transaction_list.append((Account._current_time(), self.__balance))
def deposit(self, amount):
if amount > 0:
self.__balance += amount
print("Balance deposited {}".format(amount))
self.show_balance()
self._transaction_list.append((Account._current_time(), amount))
def withdraw(self, amount):
if 0 < amount <= self.__balance:
self.__balance -= amount
print("Amount Withdrawn {}".format(amount))
self._transaction_list.append((Account._current_time(), -amount))
else:
print("Insufficient Balance in Account to Withdraw")
self.show_balance()
def show_balance(self):
print("Balance is {}".format(self.__balance))
def show_transaction(self):
for date, amount in self._transaction_list:
if amount > 0:
trans_type = "deposited"
else:
trans_type = "withdrawn"
amount *= -1
print("{:6} {} on {}".format(amount, trans_type, date, date.astimezone()))
if __name__ == "__main__":
Satyam = Account("Satyam", 0)
Satyam.show_balance()
Satyam.withdraw(500)
Satyam.deposit(1000)
Satyam.withdraw(500)
Satyam.withdraw(2000)
Satyam.show_transaction()
account2 = Account("account2", 800)
account2.deposit(100)
account2.withdraw(200)
account2.__balance = 200
account2.show_transaction()
account2.show_balance()
print(account2.__dict__)