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...

1 answer below »
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="">
Answered Same DaySep 26, 2020

Answer To: ReadingTransactions/123456.txt 123456 7890 1000 0.33 Deposit 300 Deposit 800 Withdrawal 200...

Amit answered on Sep 29 2020
148 Votes
34304/bankaccount.py
from tkinter import messagebox
class BankAccount:
acc_no = '0'
PIN = ''
bal = 0.0
interestRate = 0.0
amt = 0.0
transaction = ""
transList = []
def __init__(self):
acc_no = '0'
PIN = ''
bal = 0.0
interestRate = 0.0
transList = []
def deposit_funds(self, amount):
try:
temp_amount = float(amount)
except:
rai
se Exception("Alert", "Please enter a valid amount")
if temp_amount < 0:
raise Exception("Alert", "Bad Amount")
return BankAccount.bal + float(amount)
def withdraw_funds(self, amount):
try:
temp_amount = float(amount)
except:
raise Exception("Alert", "Please enter a valid amount")
if temp_amount < 0:
raise Exception("Alert", "Bad Amount")
if temp_amount > BankAccount.bal:
raise Exception("Alert", "Bad Amount")
return BankAccount.bal - float(amount)
def get_transaction_string(self):
tup = (BankAccount.transaction , BankAccount.amt)
BankAccount.transList.append(tup)
return BankAccount.transList
def save_to_file(self):
file = open(str(BankAccount.acc_no) +'.txt',"w")
file.write(BankAccount.acc_no + '\n')
file.write(BankAccount.PIN + '\n')
file.write(str(BankAccount.bal) + '\n')
file.write(str(BankAccount.interestRate) + '\n')
for a in BankAccount.transList:
file.write(str(a[0]) + '\n')
file.write(str(a[1]) + '\n')
file.close()
34304/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()
win.geometry('440x640')
win.title('FedUni Banking')
accNo = tk.StringVar()
account_number_entry = tk.Entry(win, textvariable=accNo)
account_number_entry.focus_set()
PIN = tk.StringVar()
account_pin_entry = tk.Entry(win, text='PIN Number', textvariable=PIN)
account_pin_entry.config(show="*")
bal = tk.StringVar()
bal.set('Balance: $0.00')
balance_label = tk.Label(win, textvariable=bal)
amt_ety = tk.Entry(win)
transaction_text_widget = tk.Text(win, height=10, width=48)
bankAccount = BankAccount()
def clear_pin_entry():
account_pin_entry.delete(0, tk.END)
account_pin_entry.insert(0, "")
def handle_pin_button(event):
if account_pin_entry.get() == "":
account_pin_entry.delete(0, tk.END)
account_pin_entry.insert(0, str(event))
else:
pin = int(account_pin_entry.get())
pin = pin * 10 + event
account_pin_entry.delete(0, tk.END)
account_pin_entry.insert(0, str(pin))
def log_in():
global account
global PINety
global Acc_ety
global bal
global interest_rate
BankAccount.pin_number = account_pin_entry.get()
file = accNo.get()
file = file + ".txt"
try:
fileP=open(file, "r")
lines = fileP.readlines()
Acc_ety = accNo.get()
if BankAccount.pin_number == lines[1].rstrip():
BankAccount.account_number = Acc_ety
BankAccount.balance = float(lines[2].rstrip())
BankAccount.interest_rate = float(lines[3].rstrip())
i = 0
j = 0
for line in lines:
tup = ()
if i > 3 :
div = j % 2
if div == 0:
var1 = line.rstrip()
j = j + 1
else:
var2 = line.rstrip()
tup = (var1 , var2)
BankAccount.transaction_list.append(tup)
j = j + 1
i = i + 1
remove_all_widgets()
create_account_screen()
fileP.close()
else:
messagebox.showinfo("Alert", "Bad Pin Number")
account_pin_entry.delete(0, tk.END)
account_pin_entry.insert(0, "")
except IOError:
BankAccount.__init__
messagebox.showinfo("Alert", "Bad Account Number")
account_number_entry.delete(0,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here