Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please complete the TODO parts of the code and then parts labeled Fixme import os # TODO: Add imports for json # TODO: Read customers

Please complete the TODO parts of the code and then parts labeled Fixme

import os # TODO: Add imports for json # TODO: Read customers data file into accounts # use the open command to open the file # read the file and load the data structure in using json.loads() # close the file when done # Read File without using 'with' keyword # Delete the below line and assign accounts data from file accounts = {'selin2': {'Pin': 1234, 'Name': 'Jill Jones', 'C': 428.78, 'S': 3062.31}} # 'aaa1': {'Pin': 1234, 'Name': 'Brit Masters', 'C': 8.62, 'S': 922.07}} # Allow 3 invalid pin entries tries = 1 max_tries = 3 # In this PE exercise, we will only test the existing username username = input('Welcome to Cactus Bank! Please enter your username: ') while tries <= max_tries: # Print bank title and menu print(f'{"Cactus Bank":^30} ') selection = input('Enter pin or x to exit application: ').casefold() # determine exit, pin not found, or correct pin found if selection == 'x': break # Verify entered pin is a key in accounts elif int(selection) != accounts[username]['Pin']: # clear screen - cls for windows and clear for linux or os x os.system('cls') # os.system('clear') for mac users print(f'Invalid pin. Attempt {tries} of {max_tries}. Please Try again') if tries == max_tries: print('Locked out! Exiting program') tries += 1 else: # Successful pin entry. reset tries and save pin tries = 1 pin = selection os.system('cls') # os.system('clear') for t in range(1, 5): # Welcome customer print(f"Welcome {accounts[username]['Name']}") print(f'{"Select Account": ^20}') # Prompt for Checking or Savings while True: try: selection = input('Enter C or S for (C)hecking or (S)avings: ').upper() if selection != 'C' and selection != 'S': raise ValueError('Incorrect selection. You must enter C or S.') except ValueError as ex: print(ex) else: os.system('cls') print(f'Opening {selection} Account... ') break # End Prompt Checking or Savings print('Transaction instructions:') print(' - Withdrawal enter a negative dollar amount: -20.00.') print(' - Deposit enter a positive dollar amount: 10.50')  # FIXME: Modify the code below to display the selected account's balance with commas for thousands print(f' Balance: ${accounts[username][selection]: .2f}') amount = 0.00 try: amount = float(input(f'Enter transaction amount: ')) # FIXME: Catch appropriate exceptions not just Exception # print better error message details using exception object except Exception: print('Bad Amount - No Transaction.') amount = 0.00 # Verify enough funds in account if (amount + accounts[username][selection]) >= 0: # FIXME: round() new account balance to 2 decimal places # Do this step last after running your program. accounts[pin][selection] += amount  # FIXME: Modify formatting to add commas for thousands print(f'Transaction complete. New balance is {accounts[username][selection]: .2f}') else: print('Insufficient Funds. Transaction Cancelled.') ans = input('Press n to make another transaction or x to exit application: ').casefold() if ans[0] == 'x': tries = max_tries + 1 break # end of application loop print(' Saving data...') # TODO: Write accounts data structure to file # We can write accounts to our data file here because # this is after we exit our application loop when # the user typed x to exit. print(' Data Saved. Exiting...')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions

Question

a. How will the leader be selected?

Answered: 1 week ago