Please complete it before sep 30 I need submit in sep 30
ReadingTransactions/123456.txt 123456 7890 1000 0.33 Deposit 300 Deposit 800 Withdrawal 200 ReadingTransactions/reading_transactions.py # NOTE: Put a '123456.txt' bank account file in the same directory as this script. # ---------- Finding transactions - version 1 ---------- ''' Because we know the format of the file, we can read the entire thing and then do a little counting to figure out how many transactions we have. ''' account_file = open('123456.txt', 'r') # Open the file file_lines = account_file.readlines() # Read the contents into a list of lines account_file.close() # Close the file num_lines = len(file_lines) # How many lines do we have? num_transactions = (num_lines - 4) // 2 # The first 4 lines are account details, every other 'pair' is a transaction # Print account details print('Account Number:', file_lines[0]) print('Pin Number :', file_lines[1]) print('Balance :', file_lines[2]) print('Interest Rate :', file_lines[3]) # Print transaction details, starting from line 4 and 'moving in steps of 2' for loop in range(4, num_lines, 2): trans_type = file_lines[loop] trans_amount = file_lines[loop+1] print('Transaction: {} - {}'.format(trans_type, trans_amount)) # -------------------------------------------------------------------- print() print('*' * 50) # Waka-waka-waka-waka.... print() # -------------------------------------------------------------------- # ---------- Finding transactions - version 2 ---------- ''' Another way we can do this is to use our knowledge of the file format and read the first four lines then just KEEP ON READING lines until we fail to read another line. ''' account_file = open('123456.txt', 'r') # Get the four known properties account_number = account_file.readline() account_pin = account_file.readline() account_balance = account_file.readline() account_interest = account_file.readline() print(account_number) print(account_pin) print(account_balance) print(account_interest) # Loop to read lines from the file while True: line = account_file.readline() # Attempt to read a line if not line: # If we failed, then exit print('End of file!') break # If we did NOT fail, then the 'line' we read will be the transaction # type, so the line below it will be the transaction amount. amount = account_file.readline() print('Transaction:', line, amount) # Always close your file to release file handles and associated resources account_file.close() # -------------------------------------------------------------------- # IMPORTANT # -------------------------------------------------------------------- # Notice that this program prints each line separated by a blank line... # This is because we read in the line from the file, and the line that # we read INCLUDES the '\n' or 'new line' character. To strip this from # the input you can use [:-1] as the 'substring' - which means "go from # the beginning up to but NOT including the very last character". # # For example, print(account_number) will print precisely: # # 123456 #<---- this is an empty line because of the '\n' # # while calling print(account_number[:-1]) will print precisely: # # 123456 # [no blank line here because we did not include it when we printed the line] itech1400_assignment_2/123456.txt 123456 7890 5000.0 0.33 deposit 3000.0 deposit 4000.0 withdrawal 2000.0 itech1400_assignment_2/bankaccount.py class bankaccount(): def __init__(self): '''constructor to set account_number to '0', pin_number to an empty string, balance to 0.0, interest_rate to 0.0 and transaction_list to an empty list.''' def deposit(self, amount): '''function to deposit an amount to the account balance. raises an exception if it receives a value that cannot be cast to float.''' def withdraw(self, amount): '''function to withdraw an amount from the account balance. raises an exception if it receives a value that cannot be cast to float. raises an exception if the amount to withdraw is greater than the available funds in the account.''' def get_transaction_string(self): '''function to create and return a string of the transaction list. each transaction consists of two lines - either the word "deposit" or "withdrawal" on the first line, and then the amount deposited or withdrawn on the next line.''' def export_to_file(self): '''function to overwrite the account text file with the current account details. account number, pin number, balance and interest (in that precise order) are the first four lines - there are then two lines per transaction as outlined in the above 'get_transaction_string' function.''' itech1400_assignment_2/feduni banking.mp4 microsoft game dvr feduni banking itech1400_assignment_2/main.py import tkinter as tk from tkinter import messagebox from pylab import plot, show, xlabel, ylabel from matplotlib.backends.backend_tkagg import figurecanvastkagg from matplotlib.figure import figure from bankaccount import bankaccount win = tk.tk() # set window size here to '440x640' pixels # set window title here to 'feduni banking' # the account number entry and associated variable account_number_var = tk.stringvar() account_number_entry = tk.entry(win, textvariable=account_number_var) account_number_entry.focus_set() # the pin number entry and associated variable. # note: modify this to 'show' pin numbers as asterisks (i.e. **** not 1234) pin_number_var = tk.stringvar() account_pin_entry = tk.entry(win, text='pin number', textvariable=pin_number_var) # the balance label and associated variable balance_var = tk.stringvar() balance_var.set('balance: $0.00') balance_label = tk.label(win, textvariable=balance_var) # the entry widget to accept a numerical value to deposit or withdraw amount_entry = tk.entry(win) # the transaction text widget holds text of the accounts transactions transaction_text_widget = tk.text(win, height=10, width=48) # the bank account object we will work with account = bankaccount() # ---------- button handlers for login screen ---------- def clear_pin_entry(event): '''function to clear the pin number entry when the clear / cancel button is clicked.''' # clear the pin number entry here def handle_pin_button(event): '''function to add the number of the button clicked to the pin number entry via its associated variable.''' # limit to 4 chars in length # set the new pin number on the pin_number_var def log_in(event): '''function to log in to the banking system using a known account number and pin.''' global account global pin_number_var global account_num_entry # create the filename from the entered account number with '.txt' on the end # try to open the account file for reading # open the account file for reading # first line is account number # second line is pin number, raise exceptionk if the pin entered doesn't match account pin read # read third and fourth lines (balance and interest rate) # section to read account transactions from file - start an infinite 'do-while' loop here # attempt to read a line from the account file, break if we've hit the end of the file. if we # read a line then it's the transaction type, so read the next line which will be the transaction amount. # and then create a tuple from both lines and add it to the account's transaction_list # close the file now we're finished with it # catch exception if we couldn't open the file or pin entered did not match account pin # show error messagebox and & reset bankaccount object to default... # ...also clear pin entry and change focus to account number entry # got here without raising an exception? then we can log in - so remove the widgets and display the account screen # ---------- button handlers for account screen ---------- def save_and_log_out(): '''function to overwrite the account file with the current state of the account object (i.e. including any new transactions), remove all widgets and display the login screen.''' global account # save the account with any new transactions # reset the bank acount object # reset the account number and pin to blank this="" is="" an="" empty="" line="" because="" of="" the="" '\n'="" #="" #="" while="" calling="" print(account_number[:-1])="" will="" print="" precisely:="" #="" #="" 123456="" #="" [no="" blank="" line="" here="" because="" we="" did="" not="" include="" it="" when="" we="" printed="" the="" line]="" itech1400_assignment_2/123456.txt="" 123456="" 7890="" 5000.0="" 0.33="" deposit="" 3000.0="" deposit="" 4000.0="" withdrawal="" 2000.0="" itech1400_assignment_2/bankaccount.py="" class="" bankaccount():="" def="" __init__(self):="" '''constructor="" to="" set="" account_number="" to="" '0',="" pin_number="" to="" an="" empty="" string,="" balance="" to="" 0.0,="" interest_rate="" to="" 0.0="" and="" transaction_list="" to="" an="" empty="" list.'''="" def="" deposit(self,="" amount):="" '''function="" to="" deposit="" an="" amount="" to="" the="" account="" balance.="" raises="" an="" exception="" if="" it="" receives="" a="" value="" that="" cannot="" be="" cast="" to="" float.'''="" def="" withdraw(self,="" amount):="" '''function="" to="" withdraw="" an="" amount="" from="" the="" account="" balance.="" raises="" an="" exception="" if="" it="" receives="" a="" value="" that="" cannot="" be="" cast="" to="" float.="" raises="" an="" exception="" if="" the="" amount="" to="" withdraw="" is="" greater="" than="" the="" available="" funds="" in="" the="" account.'''="" def="" get_transaction_string(self):="" '''function="" to="" create="" and="" return="" a="" string="" of="" the="" transaction="" list.="" each="" transaction="" consists="" of="" two="" lines="" -="" either="" the="" word="" "deposit"="" or="" "withdrawal"="" on="" the="" first="" line,="" and="" then="" the="" amount="" deposited="" or="" withdrawn="" on="" the="" next="" line.'''="" def="" export_to_file(self):="" '''function="" to="" overwrite="" the="" account="" text="" file="" with="" the="" current="" account="" details.="" account="" number,="" pin="" number,="" balance="" and="" interest="" (in="" that="" precise="" order)="" are="" the="" first="" four="" lines="" -="" there="" are="" then="" two="" lines="" per="" transaction="" as="" outlined="" in="" the="" above="" 'get_transaction_string'="" function.'''="" itech1400_assignment_2/feduni="" banking.mp4="" microsoft="" game="" dvr="" feduni="" banking="" itech1400_assignment_2/main.py="" import="" tkinter="" as="" tk="" from="" tkinter="" import="" messagebox="" from="" pylab="" import="" plot,="" show,="" xlabel,="" ylabel="" from="" matplotlib.backends.backend_tkagg="" import="" figurecanvastkagg="" from="" matplotlib.figure="" import="" figure="" from="" bankaccount="" import="" bankaccount="" win="tk.Tk()" #="" set="" window="" size="" here="" to="" '440x640'="" pixels="" #="" set="" window="" title="" here="" to="" 'feduni="" banking'="" #="" the="" account="" number="" entry="" and="" associated="" variable="" account_number_var="tk.StringVar()" account_number_entry="tk.Entry(win," textvariable="account_number_var)" account_number_entry.focus_set()="" #="" the="" pin="" number="" entry="" and="" associated="" variable.="" #="" note:="" modify="" this="" to="" 'show'="" pin="" numbers="" as="" asterisks="" (i.e.="" ****="" not="" 1234)="" pin_number_var="tk.StringVar()" account_pin_entry="tk.Entry(win," text='PIN Number' ,="" textvariable="pin_number_var)" #="" the="" balance="" label="" and="" associated="" variable="" balance_var="tk.StringVar()" balance_var.set('balance:="" $0.00')="" balance_label="tk.Label(win," textvariable="balance_var)" #="" the="" entry="" widget="" to="" accept="" a="" numerical="" value="" to="" deposit="" or="" withdraw="" amount_entry="tk.Entry(win)" #="" the="" transaction="" text="" widget="" holds="" text="" of="" the="" accounts="" transactions="" transaction_text_widget="tk.Text(win," height="10," width="48)" #="" the="" bank="" account="" object="" we="" will="" work="" with="" account="BankAccount()" #="" ----------="" button="" handlers="" for="" login="" screen="" ----------="" def="" clear_pin_entry(event):="" '''function="" to="" clear="" the="" pin="" number="" entry="" when="" the="" clear="" cancel="" button="" is="" clicked.'''="" #="" clear="" the="" pin="" number="" entry="" here="" def="" handle_pin_button(event):="" '''function="" to="" add="" the="" number="" of="" the="" button="" clicked="" to="" the="" pin="" number="" entry="" via="" its="" associated="" variable.'''="" #="" limit="" to="" 4="" chars="" in="" length="" #="" set="" the="" new="" pin="" number="" on="" the="" pin_number_var="" def="" log_in(event):="" '''function="" to="" log="" in="" to="" the="" banking="" system="" using="" a="" known="" account="" number="" and="" pin.'''="" global="" account="" global="" pin_number_var="" global="" account_num_entry="" #="" create="" the="" filename="" from="" the="" entered="" account="" number="" with="" '.txt'="" on="" the="" end="" #="" try="" to="" open="" the="" account="" file="" for="" reading="" #="" open="" the="" account="" file="" for="" reading="" #="" first="" line="" is="" account="" number="" #="" second="" line="" is="" pin="" number,="" raise="" exceptionk="" if="" the="" pin="" entered="" doesn't="" match="" account="" pin="" read="" #="" read="" third="" and="" fourth="" lines="" (balance="" and="" interest="" rate)="" #="" section="" to="" read="" account="" transactions="" from="" file="" -="" start="" an="" infinite="" 'do-while'="" loop="" here="" #="" attempt="" to="" read="" a="" line="" from="" the="" account="" file,="" break="" if="" we've="" hit="" the="" end="" of="" the="" file.="" if="" we="" #="" read="" a="" line="" then="" it's="" the="" transaction="" type,="" so="" read="" the="" next="" line="" which="" will="" be="" the="" transaction="" amount.="" #="" and="" then="" create="" a="" tuple="" from="" both="" lines="" and="" add="" it="" to="" the="" account's="" transaction_list="" #="" close="" the="" file="" now="" we're="" finished="" with="" it="" #="" catch="" exception="" if="" we="" couldn't="" open="" the="" file="" or="" pin="" entered="" did="" not="" match="" account="" pin="" #="" show="" error="" messagebox="" and="" &="" reset="" bankaccount="" object="" to="" default...="" #="" ...also="" clear="" pin="" entry="" and="" change="" focus="" to="" account="" number="" entry="" #="" got="" here="" without="" raising="" an="" exception?="" then="" we="" can="" log="" in="" -="" so="" remove="" the="" widgets="" and="" display="" the="" account="" screen="" #="" ----------="" button="" handlers="" for="" account="" screen="" ----------="" def="" save_and_log_out():="" '''function="" to="" overwrite="" the="" account="" file="" with="" the="" current="" state="" of="" the="" account="" object="" (i.e.="" including="" any="" new="" transactions),="" remove="" all="" widgets="" and="" display="" the="" login="" screen.'''="" global="" account="" #="" save="" the="" account="" with="" any="" new="" transactions="" #="" reset="" the="" bank="" acount="" object="" #="" reset="" the="" account="" number="" and="" pin="" to="">---- this is an empty line because of the '\n' # # while calling print(account_number[:-1]) will print precisely: # # 123456 # [no blank line here because we did not include it when we printed the line] itech1400_assignment_2/123456.txt 123456 7890 5000.0 0.33 deposit 3000.0 deposit 4000.0 withdrawal 2000.0 itech1400_assignment_2/bankaccount.py class bankaccount(): def __init__(self): '''constructor to set account_number to '0', pin_number to an empty string, balance to 0.0, interest_rate to 0.0 and transaction_list to an empty list.''' def deposit(self, amount): '''function to deposit an amount to the account balance. raises an exception if it receives a value that cannot be cast to float.''' def withdraw(self, amount): '''function to withdraw an amount from the account balance. raises an exception if it receives a value that cannot be cast to float. raises an exception if the amount to withdraw is greater than the available funds in the account.''' def get_transaction_string(self): '''function to create and return a string of the transaction list. each transaction consists of two lines - either the word "deposit" or "withdrawal" on the first line, and then the amount deposited or withdrawn on the next line.''' def export_to_file(self): '''function to overwrite the account text file with the current account details. account number, pin number, balance and interest (in that precise order) are the first four lines - there are then two lines per transaction as outlined in the above 'get_transaction_string' function.''' itech1400_assignment_2/feduni banking.mp4 microsoft game dvr feduni banking itech1400_assignment_2/main.py import tkinter as tk from tkinter import messagebox from pylab import plot, show, xlabel, ylabel from matplotlib.backends.backend_tkagg import figurecanvastkagg from matplotlib.figure import figure from bankaccount import bankaccount win = tk.tk() # set window size here to '440x640' pixels # set window title here to 'feduni banking' # the account number entry and associated variable account_number_var = tk.stringvar() account_number_entry = tk.entry(win, textvariable=account_number_var) account_number_entry.focus_set() # the pin number entry and associated variable. # note: modify this to 'show' pin numbers as asterisks (i.e. **** not 1234) pin_number_var = tk.stringvar() account_pin_entry = tk.entry(win, text='pin number', textvariable=pin_number_var) # the balance label and associated variable balance_var = tk.stringvar() balance_var.set('balance: $0.00') balance_label = tk.label(win, textvariable=balance_var) # the entry widget to accept a numerical value to deposit or withdraw amount_entry = tk.entry(win) # the transaction text widget holds text of the accounts transactions transaction_text_widget = tk.text(win, height=10, width=48) # the bank account object we will work with account = bankaccount() # ---------- button handlers for login screen ---------- def clear_pin_entry(event): '''function to clear the pin number entry when the clear / cancel button is clicked.''' # clear the pin number entry here def handle_pin_button(event): '''function to add the number of the button clicked to the pin number entry via its associated variable.''' # limit to 4 chars in length # set the new pin number on the pin_number_var def log_in(event): '''function to log in to the banking system using a known account number and pin.''' global account global pin_number_var global account_num_entry # create the filename from the entered account number with '.txt' on the end # try to open the account file for reading # open the account file for reading # first line is account number # second line is pin number, raise exceptionk if the pin entered doesn't match account pin read # read third and fourth lines (balance and interest rate) # section to read account transactions from file - start an infinite 'do-while' loop here # attempt to read a line from the account file, break if we've hit the end of the file. if we # read a line then it's the transaction type, so read the next line which will be the transaction amount. # and then create a tuple from both lines and add it to the account's transaction_list # close the file now we're finished with it # catch exception if we couldn't open the file or pin entered did not match account pin # show error messagebox and & reset bankaccount object to default... # ...also clear pin entry and change focus to account number entry # got here without raising an exception? then we can log in - so remove the widgets and display the account screen # ---------- button handlers for account screen ---------- def save_and_log_out(): '''function to overwrite the account file with the current state of the account object (i.e. including any new transactions), remove all widgets and display the login screen.''' global account # save the account with any new transactions # reset the bank acount object # reset the account number and pin to blank>