Question: For some reason my code only accept the third user from the stored file which is Steve and denied Mike and Jane. What is the
For some reason my code only accept the third user from the stored file which is Steve and denied Mike and Jane. What is the reason and what is the right way to fix this issue? This code is in python and it would help a lot if you can provide screenshot of your answer since it's easier for me to understand. Thank you so much! Here is my code!
I have store the file in this format
Mike sorat1237# 350
Jane para432@4 400
Steve asora8731% 500
def userInfo(file_name): usernames = [] passwords = [] balances = [] with open(file_name, 'r') as file: lines file. readlines() for line in lines [2:]: username, password, balance = line.strip().split() usernames.append(username) passwords.append(password) balances.append(float (balance)) return usernames, passwords, balances def printUserInfo(file_name, usernames, passwords, balances): with open(file_name, 'w') as file: file.write('Username Password Balance ') file.write(' ============== ') for i in range(len(usernames)): file.write(f'{usernames [i]) (passwords [i]] (balances [i]) ') def deposit (balance, amount): balance + amount return balance def withdraw(balance, amount): if balance >= amount: else: balance = amount print("Oh no! You have insufficient balance!") return balance def display (balance): print("Hello! Your current balance is", balance) def newUser(usernames, passwords, balances): username = input("What is your username?") password input ("What is your password?") amountB = float(input("What is your balance?")) usernames.append(username) passwords.append(password) balances.append(amountB) print("You have successfully added a new user!") def changeUser(usernames): username = input("What is your username?") if username in usernames: else: print("You have changed to", username) return username print(username, "is not found in our system!") file name="UserInformation.txt" usernames, passwords, balances = userInfo(file_name) current_user = "' while True: print("Hello! This is BankApp!") username = input("What is your username?") password=input ("What is your password?") if username in usernames and password == passwords [usernames. index (username)]: current_user = username print("Welcome to BankApp", current_user) break else: print("Oh no! It seems like you are not in our system! Please retry") while True: print("Type D to deposit money") print("Type W to withdraw money") print("Type B to display balance"). print("Type C to change user") print("Type A to add new user") print("Type E to exit") choice = input("What do you want to do?") if choice == "D": amount = float(input("How much do you want to deposit?")) balances [usernames.index (current_user)] = deposit (balances [usernames. index (current_user)], amount) display (balances [usernames. index (current_user)]) elif choice == "W": display (balances [usernames. index (current_user)]) amount = float (input("How much do you want to withdraw?")) balances [usernames. index (current_user)] = withdraw(balances [usernames. index (current_user)], amount) display (balances [usernames. index (current_user)]) elif choice == "B": display (balances [usernames. index (current_user)]) elif choice == "C": current_user = changeUser(usernames) elif choice == "A": newUser(usernames, passwords, balances) elif choice == "E": printUserInfo(file_name, usernames, passwords, balances) print("Thank you for using BankApp! Hope you have a nice day!") else: break print("Invalid option! Please try again.")
Step by Step Solution
There are 3 Steps involved in it
File before File after running program Terminal output Code whileloopprintType D to deposit moneyTyp... View full answer
Get step-by-step solutions from verified subject matter experts
