def open_account(account_num_list, deposit_list, firstname_list, lastname_list): # 6. This func opens a new account something_is_wrong = True user_random_account_no = 0 while something_is_wrong: user_random_account_no = randrange( 100000, 999999 ) # a new bank account number is created using random range func if str( user_random_account_no ) in account_num_list: # this is to check if account number already exists something_is_wrong = True # if it dies, then get another random number by looping again else: something_is_wrong = False # of the random account number is unique, then continue through the program deposit_input = validation_code.read_nonnegative_float( 'Please enter the amount you would like to deposit: ') firstname_input = validation_code.read_nonempty_alphabetical_string( 'What is your first name ? ') # get user name lastname_input = validation_code.read_nonempty_string( 'What is your last name? ') # asking the user for last name account_num_list.append(str(user_random_account_no)) deposit_list.append(deposit_input) firstname_list.append(firstname_input) lastname_list.append(lastname_input) write_to_file(account_num_list, deposit_list, firstname_list, lastname_list) lines() print('The following details of the account have been added:') print('Account no.\t Balance\t Full name') print(user_random_account_no, '\t\t', deposit_input, '\t', firstname_input, lastname_input) lines()
def withdraw_money(account_num_list, deposit_list, firstname_list, lastname_list): # 9. Function for withdrawing money account_number = validation_code.read_nonnegative_integer( 'Please enter the account number you would like to draw ' 'money from: ') # Re-using the function of user input for account number that is used previously in close_account() function. something_is_wrong = True while something_is_wrong: # in case user does not have enough balance, he can retry and enter a different amount if str( account_number ) in account_num_list: # checking if account number is in the account number list index_of_account_number = account_num_list.index( str(account_number)) # position of account number in list user_deposit = deposit_list[ index_of_account_number] # storing user's deposit in a variable for later use user_firstname = firstname_list[ index_of_account_number] # storing user's first name in a variable user_lastname = lastname_list[ index_of_account_number] # storing user's last name in a variable lines() print('Account details:', account_number, user_deposit, user_firstname, user_lastname) # display info lines() amount_to_withdraw = validation_code.read_nonnegative_float( 'How much would you like to withdraw from your ' 'account ' + user_firstname + '? ') # withdraw if float( user_deposit ) >= amount_to_withdraw: # checking if the amount withdrawn is not bigger than balance user_deposit = float( user_deposit ) - amount_to_withdraw # deducting the amount requested by user deposit_list[ index_of_account_number] = user_deposit # changing the user's balance on the final list lines() print('Updated account details: ', account_number, user_deposit, user_firstname, user_lastname) lines() write_to_file(account_num_list, deposit_list, firstname_list, lastname_list) something_is_wrong = False else: lines() print( 'You have insufficient funds') # telling user what's wrong lines() more = validation_code.read_nonempty_string( 'Would you like another attempt to enter a different amount' ' (Y/N)? ') # asking user if they would like to withdraw a different amount for the same account if more.upper() == 'Y' or more.startswith( 'y') or more.startswith('Y'): something_is_wrong = True else: something_is_wrong = False
def deposit_money(account_num_list, deposit_list, firstname_list, lastname_list): something_is_wrong = True while something_is_wrong: account_number = validation_code.read_nonnegative_integer( 'Enter the account number you would like to deposit ' 'money into: ') # Re-using the function of user input for account number that is used previously in close_account() function. if str( account_number ) in account_num_list: # checking if account number is in the file's account number list index_of_account_number = account_num_list.index( str(account_number)) # get position of the account number user_deposit = deposit_list[ index_of_account_number] # locate user's deposit using the position of acc no. user_firstname = firstname_list[ index_of_account_number] # locate first name of user user_lastname = lastname_list[ index_of_account_number] # lcoate last name of user lines() print('Account details:', account_number, user_deposit, user_firstname, user_lastname) # user's info lines() amount_to_deposit = validation_code.read_nonnegative_float( 'How much would you like to deposit into your ' 'account ' + user_firstname + '? ') # get balanc user_deposit = float( user_deposit ) + amount_to_deposit # adding the user's deposit to his balance deposit_list[ index_of_account_number] = user_deposit # updating the list containing the user's deposit lines() print('Updated account details: ', account_number, user_deposit, user_firstname, user_lastname) lines() write_to_file(account_num_list, deposit_list, firstname_list, lastname_list) something_is_wrong = False # exit loop else: # if bank account number is wrong, then do the following lines() print('This account number does not exist' ) # notify the user of what's wrong lines() more = validation_code.read_nonempty_string( 'Would you like another attempt to enter a different account ' 'number (Y/N)? ') # asking user if they would like to try again if more.upper() == 'Y' or more.startswith('y') or more.startswith( 'Y'): # checking if yes something_is_wrong = True # then loop through again and ask for a new account number else: something_is_wrong = False # if not then just exit without doing anything
def quit_program( ): # 12. This func asks user if they need to do anything else before quitting program something_is_wrong = True while something_is_wrong: more = validation_code.read_nonempty_string( 'Do you need to do something else? (Y/N): ') # checking with user # to exit or not if more.upper() == 'Y' or more.startswith('y') or more.startswith('Y'): main() something_is_wrong = False else: print('Exiting program...') something_is_wrong = False