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

In I'd place you have to mention mu I'd number I'd is XXXXXXXXXX

1 answer below »
In I'd place you have to mention mu I'd number I'd is XXXXXXXXXX
Answered Same Day Sep 17, 2020

Solution

Snehil answered on Sep 24 2020
134 Votes
ITECH1400_Assignment_2/123456.txt
123456
7890
5000.0
0.33
Deposit
3000.0
Deposit
4000.0
Withdrawal
2000.0
ITECH1400_Assignment_2/30353625.txt
30353625
7894
1000.0
0.33
Deposit
3000.0
Deposit
4000.0
Withdrawal
2000.0
Deposit
20000.0
Withdrawal
455.0
Withdrawal
12.0
Withdrawal
1.0
Withdrawal
10000.0
Deposit
1000.0
Withdrawal
15532.0
Deposit
1000.0
ITECH1400_Assignment_2
ankaccount.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.'''
self.account_number = 0
self.pin_number = ""
self.balance = 0.0
self.interest_rate = 0.0
self.transaction_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.'''
deposit_amount = float(amount)
self.balance += deposit_amount
self.transaction_list.append(('Deposit', deposit_amount))


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.'''
withdrawal = float(amount)
if self.balance >= withdrawal:
self.balance -= withdrawal
self.transaction_list.append(('Withdrawal', withdrawal))
else:
raise ValueE
or('Insufficient Balance')



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.'''
transaction_string = ""
for transaction in self.transaction_list:
transaction_string += transaction[0] + "\n" + str(transaction[1]) + "\n"
return transaction_string


def export_to_file(self):
'''Function to overwrite the account text file with the cu
ent 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.'''
account_file = open(str(self.account_number)+".txt","w")
account_file.write(str(self.account_number) + "\n")
account_file.write(self.pin_number + "\n")
account_file.write(str(self.balance) + "\n")
account_file.write(str(self.interest_rate) + "\n")
account_file.write(self.get_transaction_string())
account_file.close()
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()
win.geometry('440x640')# Set window size here to '440x640' pixels
win.title('FedUni Banking')# Set window title here to 'FedUni Banking'
win.resizable(False,False)
# 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()
account_number_var.set("30353625")
# 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, show="*", text='PIN Number', textvariable=pin_number_var)
pin_number_var.set("7894")
# 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()
# ---------- Button Handlers for Login Screen ----------
def clear_pin_entry(event):
'''Function to clear the PIN number entry when the Clear / Cancel button is clicked.'''
pin_number_var.set("")# 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
value = pin_number_var.get()
if len(value) >= 4:
pin_number_var.set(value[:4])
return
# Set the new pin number on the pin_number_va
pin_number_var.set(value+event.widget.cget("text"))
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
global account_file

# Create the filename from the entered account number with '.txt' on the end
account_file_name = account_number_var.get() + ".txt"
# Try to open the account file for reading
try:
# Open the account file for reading
account_file = open(account_file_name,"r")
# First line is account numbe
account.account_number = int(read_line_from_account_file())
# Second line is PIN number, raise exceptionk if the PIN entered doesn't match account PIN read
account_pin = read_line_from_account_file()
if pin_number_var.get() != account_pin:
raise ValueE
or('Pin Mismatch')
account.pin_number = account_pin

# Read third and fourth lines (balance and interest rate)
account.balance = float(read_line_from_account_file())
account.interest_rate = float(read_line_from_account_file())

# Section to read account transactions from file - start an infinite 'do-while' loop here
while True:
# 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
line = read_line_from_account_file()
if line == '':

eak
else:
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here