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 »
My order quote


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_funds(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_funds(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="" save_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/itech1400_assignment_2_feduni_banking.pdf="" itech1400="" –="" foundations="" of="" programming="" school="" of="" science,="" engineering="" and="" information="" technology="" cricos="" provider="" no.="" 00103d="" page="" 1="" of="" 10="" itech1400="" -="" assignment="" 2="" –="" feduni="" banking="" due="" date:="" 5pm,="" friday="" of="" week="" 11="" this="" assignment="" will="" test="" your="" skills="" in="" designing="" and="" programming="" applications="" to="" specification="" and="" is="" worth="" 20%="" of="" your="" non-invigilated="" (type="" a)="" marks="" for="" this="" course.="" this="" is="" an="" individual="" assignment="" –="" and="" while="" you="" may="" discuss="" it="" with="" your="" fellow="" students,="" you="" must="" not="" share="" designs="" or="" code="" or="" you="" will="" be="" in="" breach="" of="" the="" university="" plagiarism="" rules.="" this="" assignment="" should="" take="" you="" approximately="" 20="" hours="" to="" complete.="" assignment="" overview="" you="" are="" tasked="" with="" creating="" an="" application="" that="" uses="" a="" gui="" that="" simulates="" a="" simple="" banking="" interface="" similar="" to="" an="" atm="" online="" banking="" using="" the="" python="" 3="" programming="" language.="" the="" assignment="" is="" broken="" up="" into="" five="" main="" components:="" 1.)="" the="" ability="" to="" provide="" an="" account="" number="" and="" a="" pin="" (personal="" identification="" number)="" to="" sign="" into="" a="" bank="" account,="" 2.)="" the="" ability="" to="" view="" the="" balance="" of="" the="" bank="" account="" and="" to="" deposit="" and="" withdraw="" virtual="" money="" into="" and="" out="" from="" the="" account,="" 3.)="" the="" ability="" to="" save="" transactions="" via="" file="" storage="" so="" that="" you="" can="" log="" in,="" deposit="" some="" money="" and="" then="" log="" out="" –="" and="" when="" you="" log="" back="" in="" that="" money="" is="" still="" there,="" and="" finally="" 4.)="" the="" ability="" to="" display="" a="" graph="" of="" projected="" earnings="" on="" the="" bank="" account="" via="" the="" compound="" interest="" accrued="" over="" a="" variable="" amount="" of="" time.="" 5.)="" a="" test="" case="" that="" ensures="" your="" bankaccount's="" deposit="" and="" withdraw="" functionality="" operates="" correctly.="" your="" submission="" should="" consist="" of="" three="" python="" scripts="" that="" implement="" this="" application="" as="" described="" in="" the="" following="" pages:="" bankaccount.py,="" main.py="" along="" with="" a="" testbankaccount.py="" which="" contains="" a="" small="" test="" case="" with="" a="" few="" simple="" unit="" tests="" than="" ensure="" that="" your="" bank="" accounts="" deposit_funds="" and="" withdraw_funds="" methods="" operate="" correctly.="" you="" are="" provided="" with="" a="" 'stub'="" of="" each="" of="" these="" files="" which="" contain="" all="" the="" function="" declarations="" and="" comments="" which="" describe="" the="" role="" of="" the="" function="" and="" how="" it="" can="" be="" put="" together,="" but="" you="" will="" have="" to="" write="" the="" code="" for="" vast="" majority="" of="" the="" functions="" yourself.="" you="" are="" also="" provided="" with="" a="" stub="" of="" the="" bankaccounttestcase.py="" file.="" your="" final="" submission="" should="" be="" a="" zipped="" archive="" (i.e.="" ‘zip="" file’)="" containing="" your="" completed="" python="" scripts.="" there="" is="" no="" word="" processed="" component="" to="" this="" second="" assignment.="" itech1400="" –="" foundations="" of="" programming="" school="" of="" science,="" engineering="" and="" information="" technology="" cricos="" provider="" no.="" 00103d="" page="" 2="" of="" 10="" bank="" account="" class="" design="" the="" design="" for="" a="" bankaccount="" object="" is="" laid="" out="" in="" the="" following="" class="" diagram:="" as="" you="" might="" imagine,="" the="" deposit_funds(amount)="" function="" adds="" that="" money="" to="" the="" current="" balance="" of="" the="" account,="" and="" the="" withdraw_funds(amount)="" function="" removes="" (i.e.="" subtracts)="" money="" from="" the="" current="" balance="" of="" the="" account.="" each="" transaction="" in="" the="" transaction_list="" is="" a="" tuple="" containing="" either="" the="" word="" deposit="" or="" the="" word="" withdrawal="" followed="" by="" an="" amount,="" for="" example:="" ("deposit",="" 300.0)="" or="" ("withdrawal",="" 100.0).="" the="" bank="" accounts="" in="" our="" program="" do="" not="" have="" an="" overdraft="" facility="" so="" the="" user="" cannot="" withdraw="" money="" they="" do="" not="" have="" –="" that="" is,="" if="" they="" had="" $200="" in="" their="" account="" and="" they="" tried="" to="" withdraw="" more="" than="" $200="" then="" the="" operation="" should="" fail="" and="" the="" withdraw_funds="" function="" should="" raise="" an="" exception="" with="" a="" suitable="" error="" message="" which="" is="" caught="" and="" displayed="" in="" the="" main.py="" file="" where="" the="" operation="" was="" attempted.="" all="" error="" messages="" such="" as="" those="" from="" exceptions="" should="" be="" displayed="" in="" a="" pop-up="" messagebox.="" the="" get_transaction_string="" method="" should="" loop="" over="" all="" the="" transactions="" in="" the="" transaction_list="" creating="" a="" string="" version="" (with="" newline="" characters)="" of="" all="" the="" transactions="" associated="" with="" the="" account.="" the="" save_to_file="" function="" should="" save="" the="" account_number,="" pin_number,="" balance,="" and="" interest_rate="" in="" that="" order="" to="" a="" file="" called="">.txt followed by the transaction list string generated from the get_transaction_string() method. The name of the account file is NOT '.txt' - the name of the file is the ACTUAL ACCOUNT NUMBER followed by ".txt", so for an account with account_number 123456 the name of the account file would be 123456
Answered Same DayMay 30, 2020ITECH1400

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

Abr Writing answered on May 31 2020
157 Votes
123456.txt
123456
7890
9000.0
0.33
Deposit
3000.0
Deposit
4000.0
Withdrawal
2000.0
Deposit
4000.0
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
win.geometry('440x640')
# Set window title here to 'FedUni Banking'
win.title('FedUni Banking')
# The account number entry and associated variable
account_number_var = tk.StringVar()
account_number_entry = tk.E
ntry(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, show='*')
# 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
pin_number_var.set(None)
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
pin_number = account_pin_entry.get()
# Set the new pin number on the pin_number_var
if len(pin_number) < 4:
pin_number_var.set(pin_number+str(event))
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_number_entry
# Create the filename from the entered account number with '.txt' on the end
# Try to open the account file for reading
try:
with open(account_number_entry.get()+'.txt') as f:
# Open the account file for reading
index = 0
# First line is account number
for line in f:
line = line.strip()
if index == 0:
account.account_number = line
# Second line is PIN number, raise exceptionk if the PIN entered doesn't match account PIN read
elif index == 1:
account.pin_number = line
if account.pin_number != pin_number_var.get():
raise Exception('Incorrect PIN number')
# Read third and fourth lines (balance and interest rate)
elif index == 2:
account.balance = float(line)
elif index == 3:
account.interest_rate = float(line)
# Section to read account transactions from file - start an infinite 'do-while' loop here
elif index % 2 == 0:
typ = line
else:
amount = line
account.transaction_list.append((typ, amount))
# 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
index += 1
# 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
except:
# Show error messagebox and & reset BankAccount object to default...
raise Exception('Account Not Found')
# ...also clear PIN entry and change focus to account number entry
pin_number_var.set('')
# 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 ----------
create_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
account.save_to_file()
# Reset the bank acount object

# Reset the account number and pin to blank
account_number_var.set('')
pin_number_var.set('')
# Remove all widgets and display the login screen again
remove_all_widgets()
create_login_screen()
def perform_deposit():
'''Function to add a deposit for the amount in the amount entry to the
account's transaction list.'''
global account
global amount_entry
global balance_label
global balance_var
# Try to increase the account balance and append the deposit to the account file
try:
# Get the cash amount to deposit. Note: We check legality inside account's deposit method
account.deposit_funds(amount_entry.get())
# Deposit funds

# Update the transaction widget with the new transaction by calling account.get_transaction_string()
# Note: Configure the text widget to be state='normal' first, then delete contents, then instert new
# contents, and finally configure back to state='disabled' so it cannot be user edited.
transaction_text_widget.configure(state='normal')
transaction_text_widget.delete(1.0, tk.END)
for transaction in account.get_transaction_string().split(' '):
transaction_text_widget.insert(tk.END, transaction+'\n')
transaction_text_widget.configure(state="disabled")

# Change the balance label to reflect the new balance
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here