-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank.py
96 lines (69 loc) · 2.35 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def decorator(func):
def wrapper(*args, **kwargs):
print("Action completed")
func(*args, **kwargs)
return wrapper
import time
import acc
class Banckaccount(object):
name_of_bank = "CSS INTERNATIONAL BANK"
def __init__(self, name, passw, balance):
self.name = name
self.passw = passw
self.balance = balance
def deposit(self, amount):
self.balance += amount
print(f"{amount} deposited..")
return self.balance
def withdraw(self, amount):
if amount < self.balance:
self.balance -= amount
print(f"{amount} withdrawn..")
return self.balance
else:
print("Insufficient balance")
def __str__(self):
return f"User: {self.name} --------> Balance: {self.balance}"
def create_account():
file = open("acc.py", "a")
name = input("Please enter your name: ")
password = input("Please set your password: ")
file.write("\n{} = ['{}', {}]".format(name, password, 0))
def main():
file = open("acc.py", "a")
name = input("Enter your name: ")
try:
user = eval(f"acc.{name}")
passw = user[0]
print("Please wait.....")
time.sleep(2)
password = input("Enter your password: ")
if passw != password:
print(f"incorrect password")
exit()
balance = user[1]
main_user = Banckaccount(name, passw, balance)
action = input("Deposit[d]-------Withdraw[w]")
if action.lower() == "d":
amount = input("Enter amount: \n")
print("please wait")
time.sleep(2)
balance = main_user.deposit(int(amount))
file.write("\n{} = ['{}', {}]".format(name, passw, balance))
elif action.lower() == "w":
amount = input("Enter amount: \n")
print("please wait")
time.sleep(2)
balance = main_user.withdraw(int(amount))
file.write("\n{} = ['{}', {}]".format(name, passw, balance))
else:
print("Incorrect choice....")
exit()
except AttributeError:
print("Account does not exit....")
if __name__ == "__main__":
about = input("Do you already have an account (y/n): ")
if about == "y":
main()
else:
create_account()