-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank.py
59 lines (47 loc) · 1.8 KB
/
bank.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
from datetime import datetime
class Account:
def __init__(self,name,phoneNumber,loan):
self.name=name
self.phoneNumber=phoneNumber
self.balance=0
self.loan=loan
self.statement=[]
def showBalance(self):
return f"Hello {self.name},your balance is kshs.{self.balance}."
def deposit(self,amount):
if(amount<0):
return f"You cannot deposit less than 0"
else:
self.balance+=amount
now=datetime.now()
transaction={"amount":amount,"time":now,"narration":"You deposited"}
self.statement.append(transaction)
return self.showBalance()
def show_statement(self):
for transaction in self.statement:
amount=transaction["amount"]
narration=transaction["narration"]
time=transaction["time"]
date=time.strftime("%d/ %m / %y")
print(f"{date}:{narration}:{amount}")
def withdraw(self,amount):
if(amount>self.balance):
return f"Your balance is {self.balance}.You cannot withdraw {amount}"
else:
self.balance-=amount
now=datetime.now()
transaction={"amount":amount,"time":now,"narration":"You have withdrawn"}
self.statement.append(transaction)
return self.showBalance()
def borrow(self,amount):
self.amount=amount
if (amount>0):
return f"You can borrow{amount}"
else:
return f"You cannot borrow less than zero"
def repay_loan(self,amount):
self.amount=amount
if(amount>0):
return f"Please repay your outstanding loan of{amount}"
else:
return f"You have cleared your loan!"