Answer:
# global variable for logged in users
loggedin = []
# create the user account list as a dictionary called "bank".
def import_and_create_dictionary(filename):
bank = {}
i = 1
with open(filename, "r") as file:
for line in file:
(name, amt) = line.rstrip('\n').split(":")
bank[i] = [name.strip(), amt]
i += 1
return bank
#create the list of user login details.
def import_and_create_accounts(filename):
acc = []
with open(filename, "r") as file:
for line in file:
(login, password) = line.rstrip('\n').split("-")
acc.append([login.strip(), password.strip()])
return acc
# function to login users that are yet to login.
def signin(accounts, login, password):
flag="true"
for lst in accounts:
if(lst[0]==login and lst[1] == password):
for log in loggedin:
if(log ==login):
print("You are already logged in")
flag="false"
break
else:
flag="false"
if(flag=="true"):
loggedin.append(login) # adding user to loggedin list
print("logged in succesfully")
return True
return False
# calling both the function to create bank dictionary and user_account list
bank = import_and_create_dictionary("bank.txt")
print (bank)
user_account = import_and_create_accounts("user.txt")
print(user_account)
# check for users loggedin
signin(user_account,"Brandon","123abcAB")
signin(user_account,"James","100jamesABD")
signin(user_account,"Sarah","sd896ssfJJH")
Explanation:
The python program is a banking application system that creates a list of user accounts and their login details from the bank.txt and user.txt file. The program also uses the information to log in and check for users already logged into their account with the "loggedin" global variable.