-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple account.py
More file actions
57 lines (46 loc) · 1.56 KB
/
Copy pathSimple account.py
File metadata and controls
57 lines (46 loc) · 1.56 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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.transactionList = []
print("Account created for {}.".format(self.name))
def deposit(self, amount):
if amount > 0:
self.balance += amount
self.showBalance()
self.transactionList.append((Account._current_time(), amount))
def withdraw(self, amount):
if 0 < amount <= self.balance:
self.balance -= amount
self.transactionList.append((Account._current_time(), -amount))
else:
print("Invalid Transaction.")
self.showBalance()
def showBalance(self):
print("Balance is {}".format(self.balance))
def transactions(self):
for date, amount in self.transactionList:
if amount > 0:
tranType = "Deposited"
else:
tranType = "Withdrawn"
amount *= -1
print("{:4} {} on {} (localtime was {}".format(amount, tranType, date, date.astimezone()))
if __name__ == "__main__":
oliseh = Account("Olisemelie", 0)
oliseh.showBalance()
oliseh.deposit(5000)
# oliseh.showBalance()
oliseh.withdraw(3000)
# oliseh.showBalance()
oliseh.deposit(3000)
oliseh.withdraw(1000000)
oliseh.transactions()
print(oliseh.__dict__)