Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 »
ReadingTransactions/123456.txt
123456
7890
1000
0.33
Deposit
300
Deposit
800
Withdrawal
200
ReadingTransactions
eading_transactions.py
# NOTE: Put a '123456.txt' bank account file in the same directory as this script.
# XXXXXXXXXXFinding 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()
# --------------------------------------------------------------------
# XXXXXXXXXXFinding 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:
XXXXXXXXXXline = account_file.readline() # Attempt to read a line

XXXXXXXXXXif not line: # If we failed, then exit
XXXXXXXXXXprint('End of file!')

eak
# 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.
XXXXXXXXXXamount = account_file.readline()
XXXXXXXXXXprint('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
ankaccount.py
class BankAccount():
def __init__(self):
'''Constructor to set account_number to '0', pin_number to an empty string,
XXXXXXXXXXbalance 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
XXXXXXXXXXexception 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
XXXXXXXXXXexception if it receives a value that cannot be cast to float. Raises
XXXXXXXXXXan exception if the amount to withdraw is greater than the available
XXXXXXXXXXfunds in the account.'''
def get_transaction_string(self):
'''Function to create and return a string of the transaction list. Each transaction
XXXXXXXXXXconsists of two lines - either the word "Deposit" or "Withdrawal" on
XXXXXXXXXXthe 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 cu
ent account
XXXXXXXXXXdetails. Account number, pin number, balance and interest (in that
XXXXXXXXXXprecise order) are the first four lines - there are then two lines
XXXXXXXXXXper transaction as outlined in the above 'get_transaction_string'
XXXXXXXXXXfunction.'''
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
alance_var = tk.StringVar()
alance_var.set('Balance: $0.00')
alance_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()
# XXXXXXXXXXButton 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_va

def log_in(event):
'''Function to log in to the banking system using a known account number and PIN.'''
global account
global pin_number_va
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 numbe
# 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,
eak 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 e
or 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

# XXXXXXXXXXButton Handlers for Account Screen ----------
def save_and_log_out():
'''Function to overwrite the account file with the cu
ent 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
Answered Same Day Sep 26, 2020

Solution

Amit answered on Sep 29 2020
151 Votes
34304
ankaccount.py
from tkinter import messagebox
class BankAccount:
acc_no = '0'
PIN = ''
al = 0.0
interestRate = 0.0
amt = 0.0
transaction = ""
transList = []
def __init__(self):
acc_no = '0'
PIN = ''
al = 0.0
interestRate = 0.0
transList = []
def deposit_funds(self, amount):
try:
temp_amount = float(amount)
except:
aise Exception("Alert", "Please enter a valid amount")
if temp_amount < 0:
aise Exception("Alert", "Bad Amount")
eturn BankAccount.bal + float(amount)
def withdraw_funds(self, amount):
try:
temp_amount = float(amount)
except:
aise Exception("Alert", "Please enter a valid amount")
if temp_amount < 0:
aise Exception("Alert", "Bad Amount")
if temp_amount > BankAccount.bal:
aise Exception("Alert", "Bad Amount")
eturn BankAccount.bal - float(amount)
def get_transaction_string(self):
tup = (BankAccount.transaction , BankAccount.amt)
BankAccount.transList.append(tup)
eturn 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="*")
al = tk.StringVar()
al.set('Balance: $0.00')
alance_label = tk.Label(win, textvariable=bal)
amt_ety = tk.Entry(win)
transaction_text_widget = tk.Text(win, height=10, width=48)
ankAccount = 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
emove_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 IOE
or:
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