Question: ile Edit Format View Help Jpdate the code to reflect below changes. Since you're new to programming, you will be storing the account information in


ile Edit Format View Help Jpdate the code to reflect below changes. Since you're new to programming, you will be storing the account information in a text file. Below is the suggested format: 1111243.56 2222345.67 3333456.78 1. Each account will be read as AccountNumber + Space + AccountBalance 2. Write a function to read data from a text file called accounts.txt into your accounts dictionary upon starting the program 3. Write another function to overwrite accounts.txt with data from your accounts dictionary upon issuing a new quit command. 4. Refactor your program to include functions where applicable. Some examples would include deposit, withdraw, and show balance. File Edit Format View Help accounts ={} def get_account_number (): account_number = int (input("Enter account number:")) return account_number def deposit(account_number): amount = float(input("Enter deposit amount: ")) accounts[account_number] += amount print ("Deposit successful. New balance:", accounts[account_number]) def withdraw (account_number): amount = float (input ("Enter withdrawl amount: ")) if amount > accounts [account_number]: print("Insufficient balance.") else: accounts[account_number] - amount print("Withdrawal successful. New balance: ", accounts[account_number]) def check_balance(account_number): print("Account balance: ", accounts[account_number]) while True: print("1. Deposit") print("2. Withdraw") print("3. Check balance") print("4. Quit") choice = int ( input ( "Enter choice:")) if choice ==1 : account_number = get_account_number () if account_number not in accounts: accounts [account_number ]=0.0 deposit(account_number) elif choice =2 : account_number = get_account_number () if account_number not in accounts: accounts [account_number ]=0.0 withdraw (account_number) elif choice ==3 : account_number = get_account_number () if account_number not in accounts: accounts[account_number ]=0.0 check_balance (account_number) elif choice =4 : break else: print("Invalid choice")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
