Question
Complete the code for the TODO parts and correct the code for the FIXME parts (python code) # Comment with name, class, time, and PE1
Complete the code for the TODO parts and correct the code for the FIXME parts (python code)
# Comment with name, class, time, and PE1 # os allows us to clear the screen in a actual console or terminal import os import random
# TODO: modify the users data structure # key = username, value = account dictionary # account dictionary has 4 items # Create objects for balances and transaction accounts = {'selin2': 9999} account = 1000.00 pin = 0 ans = ''
# Allow 3 invalid pin entries tries = 1 pin_tries = 1 max_tries = 3 pin_found = False
username = input('Welcome to Cactus Bank. Please enter your username: ')
if username not in accounts: print(f"{username}, Didn't find your username.") ans = input("Do you want to create an account (Y/N)? ").lower() if ans[0] != 'y': print('Thank you for visiting Catcus Bank. Come back soon.') tries = max_tries + 1 else: ans1 = int(input('Enter 1 to create a pin yourself or 2 and the system will create a pin for you: ')) if ans1 == 1: while pin_tries <= max_tries: pin = int(input('Select a number between 1 and 9999 as your pin: ')) print(pin) if 0 < pin < 10000: accounts[username] = pin pin_found = True pin_tries = max_tries + 1 else: print('Invalid pin entered.') pin_tries += 1 if pin_tries > max_tries: print('Please try later ....') tries = max_tries + 1 elif ans1 == 2: pin = random.randint(1, 9999) print("Your pin is: ", pin) accounts[username] = pin tries = 1 pin_found = True else: print('Invalid option! Thank you for visiting Catcus Bank. Come back soon.') tries = max_tries + 1
if pin_found: print("Please remember your pin.") print("The system will require you to enter it again.") input("Press Enter to continue...") # os.system('cls') for windows os.system('clear')
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 # FIXME: Verify entered pin is the same as the pin stored in the accounts dictionary elif selection != pin: # clear screen - cls for windows and clear for linux or os x os.system('cls') # os.system('clear')
print(f'Invalid pin. Attempt {tries} of {max_tries}. Please Try again') if tries == max_tries: print('Locked out! Exiting program') # increment tries tries += 1 else: # Upgrade: successful pin entry. reset tries and save pin tries = 1 pin = selection
# clear screen os.system('cls')
# TODO: Welcome customer # Display Welcome
# TODO: Add prompt for Checking or Savings # Entry must be C or S to use as a key for the account balances # Use a loop and exception handling to ensure input is good # reuse selection name to store input to avoid scope issues
# Upgrade: Removed slicing and w/d entry - New Instructions print('Transaction instructions:') print(' - Withdrawal enter a negative dollar amount: -20.00.') print(' - Deposit enter a positive dollar amount: 10.50')
# Upgrade: removed for loop only 1 transaction per pin input
# FIXME: All references to account need to be fixed # accounts is the new dictionary that needs to be indexed # using the entered username and the selection account type print(f' Balance: ${account: .2f}')
# TODO: Add exception handling for user entry of amount # Good input - convert to float and store in amount # Exception - Print Bad Amount and set amount to zero amount = float( input(f'Enter transaction amount: ').casefold())
# Upgrade: Verify enough funds in account # FIXME: All references to account need to be fixed # add indices for pin and selection holding account type if (amount + account) >= 0: account += amount print(f'Transaction complete. New balance is {account: .2f}') else: print('Insufficient Funds. Transaction Cancelled.')
# end of application loop
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started