Develop a class BankAccount where each created object will have a single instanc
ID: 3769133 • Letter: D
Question
Develop a class BankAccount where each created object will have a single instance variable called balance of type float. It support the following methods/ functions: Constructor: Takes a float bal as parameter and initializes the balance to this bal. withdraw: Takes no parameters, asks the user to input an amount and deducts this amount from the balance. deposit: Takes no parameters, asks the user to input an amount, and adds this amount to the balance. Get balance: Takes no parameters, and returns the balance of the account. Outside of the doss, create 5 bank accounts and test your class. For e.g., one bank account testing could be: acc1 a BankAccount (700) acc1 .withdraw acc .deposit print ("The account balance is + str(accl.getbalance)) could produce the following (assuming I input 10 and 20 as withdrawal and deposit respectively) Please enter amount to withdraw: 10 Please enter amount to deposit: 20 The account balance Is 710Explanation / Answer
import filestore
import time
import datetime
WELCOME_MESSAGE = "wlcome to bank" + " "
def postbank():
print (WELCOME_MESSAGE)
prompts = {
1: BankAccount,
2: ReturnCustomer
}
while True:
prompt = int(raw_input("new account , Press 1" + " "
+ " to access account & press 2:" + " "))
if prompt in prompts:
prompts[prompt]()
else:
print "invalid key try again"
class BankAccount:
def __init__(self):
self.client_name
self.client_password
self.balance = filestore.cus_account_check()
print ("Thank you {clientname}, account accsed start the process,".format(clientname=self.clientname)
+ " " + "a 500 rs has been credited to your account")
self.client_functions()
def client_functions(self):
print(" To select your option from following key")
print ("To:" + " "
+ "Check Balance, press B" + " "
+ "Deposit cash: press D" + " "
+ "Withdraw cash, press W" + " "
+ "Delete account press X" + " "
+ "Exit service, press E" + " ")
functions = {
'b': self.check_balance,
'd': self.deposit_cash,
'w': self.withdraw_cash,
}
while True:
answer = raw_input("> ").lower()
if answer in functions:
self.pass_check()
functions[answer]()
elif answer is 'x':
print ("{clientname}, account is being deleted".format(clientname=self.clientname))
file_store.delete_account(self.clientname)
print (" account has been successfuly deleted, .")
elif answer is 'e':
print ("Thank you ")
print ("Goodbye {clientname}".format(clientname=self.clientname))
exit()
else:
print "invalid key, please try again"
def check_balance(self):
date = datetime.date.today().strftime('%d-%B-%Y')
print (" account balance as at {time} is {balance}").format(time=date, balance=self.balance)
self.transact_again()
def withdraw_cash(self):
amount = float(raw_input(" enter amount for withdraw:" + " "))
self.balance -= amount
print (" new account balance is {balance}".format(balance=self.balance) + " ")
file_store.balance_update(self.clientname, -amount)
self.transact_again()
def deposit_cash(self):
amount = float(raw_input(" enter amount to deposit:" + " "))
self.balance += amount
print (" new account balance is {balance}".format(balance=self.balance) + " ")
file_store.balance_update(self.clientname, -amount)
self.transact_again()
def transact_again(self):
while True:
answer = raw_input("want to continue? (y/n)" + " ").lower()
if ans is 'y':
self.client_functions()
elif ans is 'n':
print ("Thank you .")
print ("Goodbye {clientname}").format(clientname=self.clientname)
exit()
elif ans is not in ['y', 'n']:
print "invalid key , please choose either 'N' or 'Y'"
def pass_check(self):
attempts = 3
while attempts > 0:
answer = raw_input("if you want to continue enter password:" + " ")
if answer is self.client_password:
return True
else:
print "That is the wrong password"
attempts -= 1
print ("{attempts} more attempt(s) remaining".format(attempts=attempts))
print ("wrong password account blocked," + " "
+ "Contact your bank for help.")
exit()
class ReturnCustomer():
def __init__(self):
self.clientname
self.client_password
self.balance = file_store.old_customer_check()
self.client_functions()
postbank()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.