-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_program.py
More file actions
175 lines (154 loc) · 7.23 KB
/
client_program.py
File metadata and controls
175 lines (154 loc) · 7.23 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import banking_functions as abc
from pathlib import Path
DIR_DATA = Path("data")
if __name__ == "__main__":
data_fname = input("Enter the name of the client file to use: ")
valid_name = 0
while not valid_name:
try:
clients_file = open(DIR_DATA.joinpath(data_fname))
valid_name = 1
except:
print("ERROR! Invalid filename.")
data_fname = input("Enter the name of the client file to use: ")
valid_name = 0
client_to_accounts = abc.load_financial_data(clients_file)
while True:
# Validate user
print("------ Welcome to ABC's automated banking service. ------")
client_name = input("Please enter your name as <Firstname> <Lastname>: ")
client_sin = input(
"""For secondary authentication, please enter your SIN as ### ### ###: """
)
client_sin = client_sin.strip()
client_sin = int("".join(client_sin.split()))
is_valid_identity = abc.validate_identity(
client_to_accounts, client_name, client_sin
)
if not is_valid_identity:
print("Your credentials do not match any profiles on record. Goodbye.")
else:
print(
"""Your credentials have been succesfully validated.
Please choose from the following banking options:"""
)
options = [
"Make a transaction",
"Check total balance",
"Apply for a loan",
"Check account balances",
"Check savings goal",
"Sign out",
]
client_option = None
while client_option != 6:
print("\n\n")
client = (client_name, client_sin)
for i in range(len(options)):
print("({}) ".format(i + 1) + options[i])
print(
"""**Indicate the number of the option you would like to select**"""
)
client_option = int(input(">>>>>>>>>>> "))
if client_option == 1:
print("Indicate an account to perform a transaction:")
abc.display_client_accounts(client_to_accounts, client)
account_number = int(
input(
"**Enter 0 for Chequing, or the Savings Account number**"
"\n>>>>>>>>>>> "
)
)
if account_number >= abc.get_num_accounts(
client_to_accounts, client
):
print("Invalid account number. Transaction cancelled.")
else:
account_balance = abc.get_account_balance(
client_to_accounts, client, account_number
)
account_type = ["chequing", "savings"][min(account_number, 1)]
print(
f"""Your selected {account_type} account has an """
f"""available balance of {account_balance}"""
)
transaction_code = int(
input(
"""**Enter 1 to deposit, -1 to withdraw** \n"""
""">>>>>>>>>>> """
)
)
if not (transaction_code == 1 or transaction_code == -1):
print("Invalid transaction code. Transaction cancelled.")
else:
ttype = ["", "deposit", "withdraw"][transaction_code]
transaction_amount = float(
input(
f"Enter the amount you would like to {ttype}\n"
">>>>>>>>>>> "
)
)
if (
transaction_code == abc.WITHDRAW_CODE
and transaction_amount > account_balance
):
print("Insufficient funds. Transaction cancelled.")
else:
abc.update_balance(
client_to_accounts,
client,
account_number,
transaction_amount,
transaction_code,
)
new_account_balance = abc.get_account_balance(
client_to_accounts, client, account_number
)
print(
"Your {} account now has a balance of {}.".format(
account_type, new_account_balance
)
)
elif client_option == 2:
print(
"Your total balance across all accounts is {}".format(
sum(client_to_accounts[client][abc.BALANCES])
)
)
elif client_option == 3:
loan_amount = float(
input("**Enter the required loan amount**\n>>>>>>>>>>> ")
)
if abc.get_loan_status(client_to_accounts, client, loan_amount):
print(f"Your loan amount {loan_amount} was approved!")
else:
loan_score = abc.get_loan_score(
client_to_accounts, client, loan_amount
)
print(
f"Your loan score of {loan_score} was not sufficient "
f"to get approved (min: {abc.LOAN_APPROVAL_CUTOFF})"
)
elif client_option == 4:
print("Your account balances are:")
abc.display_client_accounts(client_to_accounts, client)
elif client_option == 5:
savings_goal = float(
input("**Enter a desired savings amount**\n>>>>>>>>>>> ")
)
savings_period = abc.time_to_client_goal(
client_to_accounts, client, savings_goal
)
client_fv = abc.get_fv_from_accounts(
client_to_accounts[client][abc.BALANCES],
client_to_accounts[client][abc.INTEREST_RATES],
savings_period,
)
print(
f"You will reach your savings goal in {savings_period} year(s)"
f", with an amount of {client_fv:.2f}"
)
elif client_option == 6:
print("Thank you for choosing ABC. Goodbye.")
else:
print("Invalid option")