forked from blindma1den/Programming-Skills-Level0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_Banking_System.py
139 lines (119 loc) · 4.95 KB
/
1_Banking_System.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'''
1. Create an online [banking system] with the following features:
* Users must be able to [log in] with a username and password.
* If the user enters the wrong credentials [three times], the system must [lock them out].
* The initial [balance] in the bank account is [$2000].
* The system must allow users to [1] deposit, [2] withdraw, [3] view, and [4] transfer money.
* The system must [display a menu] for users to perform transactions.
'''
user_db = 'Acru-Beast'
password_db = 'P455W0RD'
max_tries = 3
operation = 0
balance = 2000
in_transit = 0
status = 'none'
def error(max_tries, tries):
global status
if tries != max_tries:
print('Invalid username or password. Please try again.')
print('tries left: ' + str(max_tries - tries))
else:
print('Too many login attempts. Please try again later.\n')
status = 'WRONG'
def credentials(user_db, password_db, max_tries):
global status
tries = 0
while tries < max_tries:
user = input('\nType your username: ')
password = input('Type your password: ')
print()
if user != user_db or password != password_db:
tries += 1
error(max_tries, tries)
else:
print('Welcome Back\n')
status = 'OK'
break
def menu():
print("╔════════════════════════╗")
print("║ MENU ║")
print("╠════════════════════════╣")
print("║ [1] Deposit ║")
print("║ [2] Withdraw ║")
print("║ [3] View Balance ║")
print("║ [4] Transfer Money ║")
print("║ [5] Exit ║")
print("╚════════════════════════╝")
print()
def deposit():
global balance
deposit = int(input('\nHow much would you like to deposit?: '))
balance = balance + deposit
print("╔════════════════════════╗")
print("║ SUCCESSFUL ║")
print("╠════════════════════════╣")
print('║ New balance: $' + str(balance))
print("╚════════════════════════╝")
print()
return deposit
def withdraw():
global balance
withdraw = int(input('\nHow much would you like to withdraw?: '))
new_balance = balance - withdraw
if new_balance < 0:
print('Insufficient funds. Try again.')
menu_logic(2)
else:
balance = balance - withdraw
print("╔════════════════════════╗")
print("║ SUCCESSFUL ║")
print("╠════════════════════════╣")
print('║ New balance: $' + str(balance))
print("╚════════════════════════╝")
print()
def view_balance(balance):
print("╔════════════════════════╗")
print("║ MY BALANCE ║")
print("╠════════════════════════╣")
print('║ $' + str(balance))
print("╚════════════════════════╝")
def transfer_money():
global balance
global in_transit
transfer = int(input('\nHow much would you like to transfer?: '))
new_balance = balance - transfer
if new_balance < 0:
print('Insufficient funds. Try again.')
menu_logic(4)
else:
beneficiary = int(input('\nType the beneficiary bank account number: '))
balance = balance - transfer
in_transit = in_transit - transfer
print("╔════════════════════════╗")
print("║ SUCCESSFUL ║")
print("╠════════════════════════╣")
print('║ New balance: $' + str(balance))
print("╚════════════════════════╝")
print()
def menu_logic(operation):
if operation == 1:
deposit()
elif operation == 2:
withdraw()
elif operation == 3:
view_balance(balance)
elif operation == 4:
transfer_money()
elif operation == 5:
print('\nExiting...')
else:
print('\nError: Invalid operation number. Try again.\n')
credentials(user_db, password_db, max_tries)
if status == 'OK':
menu()
while operation != 5:
operation = int(input('Type the operation number you wish to perform: '))
menu_logic(operation)
else:
print('')