So for my project program in Python I'm suppose to code a BankApp in which the user is suppose to input their username and password to access their balance details and withdraw or deposit money. The program works though there is a small issue. See when testing I notice a problem with the withdraw and deposit function, see if I put a negative value rather than saying "invalid" and looping back to the menu it will do the opposite which I'll provide a screenshot to explain it better. Can you fix and explain how you did it(also show a sceenshot on where you fix/added code)&(UserInfo will also be provided for code to work)-Thank you.   Code def read_user_information(filename):   usernames = []   passwords = []   balances = []   try:       with open(filename, "r") as file:           lines = file.readlines()           for line in lines[2:]:               data = line.strip().split()               if len(data) == 3:                   usernames.append(data[0])                   passwords.append(data[1])                   balances.append(float(data[2]))   except FileNotFoundError:       print("User information file not found. A new file will be created.")   return usernames, passwords, balances def write_user_information(filename, usernames, passwords, balances):   with open(filename, "w") as file:       file.write("userName   passWord     Balance\n")       file.write("========================\n")       for i in range(len(usernames)):           file.write(f"{usernames[i]:<12} {passwords[i]:<12} {balances[i]:<}\n") def login(usernames, passwords):   username_input = input("Enter username: ")   password_input = input("Enter password: ")   for i, username in enumerate(usernames):       if username == username_input and passwords[i] == password_input:           return i   print("Invalid username or password. Please try again.")   return None def deposit(balances, user_index):   try:       amount = float(input("Enter the amount to deposit: "))       balances[user_index] += amount       print(f"Deposit successful. New balance: ${balances[user_index]:.2f}")   except ValueError:       print("Invalid amount entered. Deposit failed.") def withdraw(balances, user_index):   try:       amount = float(input("Enter the amount to withdraw: "))       if amount > balances[user_index]:           print("Insufficient funds. Withdrawal failed.")       else:           balances[user_index] -= amount           print(f"Withdrawal successful. New balance: ${balances[user_index]:.2f}")   except ValueError:       print("Invalid amount entered. Withdrawal failed.") def show_balance(balances, user_index):   print(f"Current balance: ${balances[user_index]:.2f}") def add_new_user(usernames, passwords, balances):   new_username = input("Enter new username: ")   new_password = input("Enter new password: ")   try:       new_balance = float(input("Enter initial balance: "))       usernames.append(new_username)       passwords.append(new_password)       balances.append(new_balance)       print(f"New user {new_username} added with balance: ${new_balance:.2f}")   except ValueError:       print("Invalid balance entered. User addition failed.") def main():   filename = "UserInformation.txt"   usernames, passwords, balances = read_user_information(filename)   user_index = None   while user_index is None:       user_index = login(usernames, passwords)   while True:       print("\nMenu:")       print("D - Deposit Money")       print("W - Withdraw Money")       print("B - Display Balance")       print("C - Change User")       print("A - Add New Client")       print("E - Exit")       choice = input("Enter your choice: ").upper()       if choice == 'D':           deposit(balances, user_index)       elif choice == 'W':           withdraw(balances, user_index)       elif choice == 'B':           show_balance(balances, user_index)       elif choice == 'C':           user_index = None           while user_index is None:               user_index = login(usernames, passwords)       elif choice == 'A':           add_new_user(usernames, passwords, balances)       elif choice == 'E':           write_user_information(filename, usernames, passwords, balances)           print("Exiting program. User information updated.")           break       else:           print("Invalid option. Please try again.") if __name__ == "__main__":   main()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

So for my project program in Python I'm suppose to code a BankApp in which the user is suppose to input their username and password to access their balance details and withdraw or deposit money. The program works though there is a small issue. See when testing I notice a problem with the withdraw and deposit function, see if I put a negative value rather than saying "invalid" and looping back to the menu it will do the opposite which I'll provide a screenshot to explain it better. Can you fix and explain how you did it(also show a sceenshot on where you fix/added code)&(UserInfo will also be provided for code to work)-Thank you.

 

Code

def read_user_information(filename):
  usernames = []
  passwords = []
  balances = []

  try:
      with open(filename, "r") as file:
          lines = file.readlines()
          for line in lines[2:]:
              data = line.strip().split()
              if len(data) == 3:
                  usernames.append(data[0])
                  passwords.append(data[1])
                  balances.append(float(data[2]))
  except FileNotFoundError:
      print("User information file not found. A new file will be created.")

  return usernames, passwords, balances


def write_user_information(filename, usernames, passwords, balances):
  with open(filename, "w") as file:
      file.write("userName   passWord     Balance\n")
      file.write("========================\n")
      for i in range(len(usernames)):
          file.write(f"{usernames[i]:<12} {passwords[i]:<12} {balances[i]:<}\n")


def login(usernames, passwords):
  username_input = input("Enter username: ")
  password_input = input("Enter password: ")

  for i, username in enumerate(usernames):
      if username == username_input and passwords[i] == password_input:
          return i
  print("Invalid username or password. Please try again.")
  return None


def deposit(balances, user_index):
  try:
      amount = float(input("Enter the amount to deposit: "))
      balances[user_index] += amount
      print(f"Deposit successful. New balance: ${balances[user_index]:.2f}")
  except ValueError:
      print("Invalid amount entered. Deposit failed.")


def withdraw(balances, user_index):
  try:
      amount = float(input("Enter the amount to withdraw: "))
      if amount > balances[user_index]:
          print("Insufficient funds. Withdrawal failed.")
      else:
          balances[user_index] -= amount
          print(f"Withdrawal successful. New balance: ${balances[user_index]:.2f}")
  except ValueError:
      print("Invalid amount entered. Withdrawal failed.")


def show_balance(balances, user_index):
  print(f"Current balance: ${balances[user_index]:.2f}")


def add_new_user(usernames, passwords, balances):
  new_username = input("Enter new username: ")
  new_password = input("Enter new password: ")
  try:
      new_balance = float(input("Enter initial balance: "))
      usernames.append(new_username)
      passwords.append(new_password)
      balances.append(new_balance)
      print(f"New user {new_username} added with balance: ${new_balance:.2f}")
  except ValueError:
      print("Invalid balance entered. User addition failed.")


def main():
  filename = "UserInformation.txt"
  usernames, passwords, balances = read_user_information(filename)

  user_index = None
  while user_index is None:
      user_index = login(usernames, passwords)

  while True:
      print("\nMenu:")
      print("D - Deposit Money")
      print("W - Withdraw Money")
      print("B - Display Balance")
      print("C - Change User")
      print("A - Add New Client")
      print("E - Exit")

      choice = input("Enter your choice: ").upper()

      if choice == 'D':
          deposit(balances, user_index)
      elif choice == 'W':
          withdraw(balances, user_index)
      elif choice == 'B':
          show_balance(balances, user_index)
      elif choice == 'C':
          user_index = None
          while user_index is None:
              user_index = login(usernames, passwords)
      elif choice == 'A':
          add_new_user(usernames, passwords, balances)
      elif choice == 'E':
          write_user_information(filename, usernames, passwords, balances)
          print("Exiting program. User information updated.")
          break
      else:
          print("Invalid option. Please try again.")


if __name__ == "__main__":
  main()

Enter username: Mike
Enter password: sorat1237#
Menu:
D - Deposit Money
W - Withdraw Money
B - Display Balance
C - Change User
A - Add New Client
E - Exit
Enter your choice: w
Enter the amount to withdraw: -300
Withdrawal successful. New balance: $593.00
Menu:
D - Deposit Money
W- Withdraw Money
B - Display Balance
C- Change User
A - Add New Client
E - Exit
Enter your choice: d
Enter the amount to deposit: -9
Deposit successful. New balance: $584.00
Transcribed Image Text:Enter username: Mike Enter password: sorat1237# Menu: D - Deposit Money W - Withdraw Money B - Display Balance C - Change User A - Add New Client E - Exit Enter your choice: w Enter the amount to withdraw: -300 Withdrawal successful. New balance: $593.00 Menu: D - Deposit Money W- Withdraw Money B - Display Balance C- Change User A - Add New Client E - Exit Enter your choice: d Enter the amount to deposit: -9 Deposit successful. New balance: $584.00
main.py x UserInformation.txt x +
=UserInformation.txt
1 userName password Balance
2
3 Mike
4
Jane
5
Steve
sorat1237#
para432@4
asora8731%
293.0
400.0
500.0
Transcribed Image Text:main.py x UserInformation.txt x + =UserInformation.txt 1 userName password Balance 2 3 Mike 4 Jane 5 Steve sorat1237# para432@4 asora8731% 293.0 400.0 500.0
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education