For some reason my code only accept the third user from the stored file which is Steve
Fantastic news! We've Found the answer you've been seeking!
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 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
Transcribed Image Text:
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\n') file.write(' ==============\n') for i in range(len(usernames)): file.write(f'{usernames [i]) (passwords [i]] (balances [i])\n') 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.") 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\n') file.write(' ==============\n') for i in range(len(usernames)): file.write(f'{usernames [i]) (passwords [i]] (balances [i])\n') 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.")
Expert Answer:
Answer rating: 100% (QA)
File before File after running program Terminal output Code whileloopprintType D to deposit moneyTyp... View the full answer
Related Book For
Applying Communication Theory For Professional Life A Practical Introduction
ISBN: 9781506315478
4th Edition
Authors: Marianne Dainton, Elaine D. Zelley
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Sara was sitting at her desk on just the second day of her new job. Her desk was relatively clear, with the exception of her computer, phone and a welcoming bouquet of flowers and balloons provided...
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
A hollow-fiber membrane device is operated to concentrate a bacterial suspension. The flow rate of cell suspension into the fibers is 350 kg/min. The inlet cell suspension is comprised of 1.0 wt%...
-
How does the treatment of medical expenses differ for AMT and regular income tax purposes?
-
Assume that a small town uses a referendum to overcome the free-ridership problem and determine how its residents might value a new water filtration system for its public water supply. The voting...
-
When may the procedure of reperformance be considered a cumpliance test? A substantive test?
-
Jupiter Company sells goods on January 1 that have a cost of $500,000 to Danone Inc. for $700,000, with payment due in 1 year. The cash price for these goods is $610,000, with payment due in 30 days....
-
A wood box weighs 92 lbs, including contents. How much horizontal force must you apply to overcome friction and start pushing the box along a wood floor in the back of a truck? Show your calculations.
-
please assist in implementing the included functions. import utils import pilots import os.path # WEATHER FUNCTIONS def bad_visibility(visibility,minimum): """ Returns True if the visibility...
-
1. Consider a network that has four nodes n1, n2, n3 and n4, and six directed arcs of the form a1 = (n1, n2), a2 = (n1, n3), a3 = (n2, n3 ), a4 = (n3), n2), a5 = (n2, n4) and a6 = (n3, n4), where the...
-
What does it mean to say that excellent networkers are givers rather than takers?
-
In what ways does communication differ in formal and informal professional networks?
-
How are clichs, dialects, defamation, and loaded language tied to credibility?
-
With whom might we have downward communication, upward communication, and lateral communication in the workplace? What are the differences among these?
-
How is libel different from slander?
-
Problem I (20 points): Given the assumptions from 2013 to 2015, please assume that the financial ratios in 2016 is the average of those of the first three years, answer the following questions....
-
Sundial Technologies produces and sells customized network systems in New Brunswick. The company offers a 60-day, all software and labor-and an extra 90-day, parts-only- warranty on all of its...
-
Lisa, Steve, and Chen were feeling triumphant. Just 3 months ago, their company, Ryan Project Systems, had merged with Gierig Strategien AG, a consulting firm headquartered in Germany. At the time,...
-
Jason was a man with a plan. Immediately after graduating from college, he created his own cleaning company. He started off cleaning houses doing all of the dirty work by himself, but over time, he...
-
For more than 80 years, Hope Medical Center had serviced its local residents as a privately run, not-for-profit community hospital. However, with the rapidly escalating cost of medical care, last...
-
Use the Chart screen (Chart ) to generate historical prices of a selected stock and its call and put options with different expirations and expiration. Select a period in which the options were...
-
Use the Chart screen (Chart ) to generate historical prices for the S\&P 500 spot, and call and put options on the index with different expirations and expiration. Select a period in which the...
-
Suppose just prior to going ex-dividend, XYZ stock is trading at \(\$ 65\) and is expected to go ex-dividend with a dividend expected to be worth \(\$2.50\) on the ex-dividend date. What advice would...
Study smarter with the SolutionInn App