Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import filestore
- import time
- import datetime
- #############################################################################
- #This is the function that is called at the beginning of the program
- def postbank(): ###
- print ("Welcome to PostBank, We care for youn") ###
- prompt=int(raw_input("""To open a new bank account, Press 1n"""+ ###
- """To access your existing account & transact press 2n""")) ###
- if prompt==1: ###
- cus=BankAccount()#creates a new customer profile ###
- elif prompt==2: ###
- cus=ReturnCustomer()#checks for existing customer ###
- else: ###
- print "You have pressed the wrong key, please try again" ###
- postbank() ###
- ###########################################################################################
- ##class for creating an instance of a new back account and other default bank functions
- class BankAccount:
- """Class for a bank account"""
- type="Normal Account"
- def __init__(self):
- ##calls functions in the module filestore
- self.username, self.userpassword, self.balance=filestore.cusaccountcheck()
- print ("Thank you %s, your account is set up and ready to use,n a 100 pounds has been credited to your account" %self.username)
- time.sleep(2)
- self.userfunctions()
- def userfunctions(self):
- print("nnTo access any function below, enter the corresponding key")
- print ("""To:
- check Balance, press B.
- deposit cash, press D.
- withdraw cash, press W.
- Delete account press X.
- exit service, press En
- :"""),
- ans=raw_input("").lower()
- if ans=='b':
- ##passcheck function confirms stored password with user input
- self.passcheck()
- self.checkbalance()
- elif ans=='d':
- self.passcheck()
- self.depositcash()
- elif ans=='w':
- self.passcheck()
- self.withdrawcash()
- elif ans=='x':
- print ("%s, your account is being deleted"%self.username)
- time.sleep(1)
- print ("Minions at work")
- time.sleep(1)
- filestore.deleteaccount(self.username)
- print ("Your account has been successfuly deleted, goodbye")
- elif ans=='e':
- print ("Thank you for using PostBank Services")
- time.sleep(1)
- print ("Goodbye %s" %self.username)
- exit()
- else:
- print "No function assigned to this key, please try again"
- self.userfunctions()
- def checkbalance(self):
- date=datetime.date.today()
- date=date.strftime('%d-%B-%Y')
- self.working()
- print ("Your account balance as at {} is {}").format(date, self.balance)
- self.transact_again()
- def withdrawcash(self):
- amount=float(raw_input("::n Please enter amount to withdrawn: "))
- self.balance-=amount
- self.working()
- print ("Your new account balance is %.2f" %self.balance)
- print ("::n")
- filestore.balupdate(self.username, -amount)
- self.transact_again()
- def depositcash(self):
- amount=float(raw_input("::nPlease enter amount to be depositedn: "))
- self.balance+=amount
- self.working()
- print ("Your new account balance is %.2f" %self.balance)
- print ("::n")
- filestore.balupdate(self.username, amount)
- self.transact_again()
- def transact_again(self):
- ans=raw_input("Do you want to do any other transaction? (y/n)n").lower()
- self.working()
- if ans=='y':
- self.userfunctions()
- elif ans=='n':
- print ("Thank you for using PostBank we value you. Have a good day")
- time.sleep(1)
- print ("Goodbye {}").format(self.username)
- exit()
- elif ans!='y' and ans!='n':
- print "Unknown key pressed, please choose either 'N' or 'Y'"
- self.transact_again()
- def working(self):
- print("working"),
- time.sleep(1)
- print ("..")
- time.sleep(1)
- print("..")
- time.sleep(1)
- def passcheck(self):
- """prompts user for password with every transaction and counterchecks it with stored passwords"""
- b=3
- while b>0:
- ans=raw_input("Please type in your password to continue with the transactionn: ")
- if ans==self.userpassword:
- return True
- else:
- print "That is the wrong password"
- b-=1
- print ("%d more attempt(s) remaining" %b)
- print ("Account has been freezed due to three wrong password attempts,n contact your bank for help, bye bye")
- time.sleep(1)
- print ("...")
- time.sleep(1)
- print("...")
- time.sleep(1)
- exit()
- class ReturnCustomer(BankAccount):
- type="Normal Account"
- def __init__(self):
- self.username, self.userpassword, self.balance=filestore.oldcuscheck()
- self.userfunctions()
- postbank() ##calling the function to run the program
- ##creating empty lists everytime the program is initialized
- cusnames=[]
- cuspasswords=[]
- cusbalance=[]
- ##opening the storage files to collect old customer data
- namefile=open("cusnamefile.txt", "r")
- passfile=open("cuspassfile.txt", "r")
- balfile=open("cusbalfile.txt", "r")
- ##populate the empty lists with data from storage files
- ##check list of customer names
- for line in namefile:
- cusnames.append(line[:-1])
- namefile.close()
- ##check list of customer passwords
- for line in passfile:
- cuspasswords.append(line[:-1])
- passfile.close()
- ##check list of customer balances
- for line in balfile:
- cusbalance.append(line[:-1])
- balfile.close()
- ##function creates a new user
- def cusaccountcheck():
- name=""
- pin=""
- while name not in cusnames and len(name)<3:
- name=raw_input("Please type in your name for this new bank accountn")
- if name not in cusnames:
- cusnames.append(name)
- filewrite(cusnames)
- break
- print("Sorry, that user name is already in use")
- ans=raw_input("Are you already a member at this bank? (y/n)n")
- if ans.lower()=='y':
- oldcuscheck()
- else:
- cusaccountcheck()
- while len(pin)<4:
- pin=raw_input("Please assign a password to this account, pin should be at least 5 charactersn")
- if len(pin)>4:
- print "your pin has been successfully saved"
- print "Remember to always keep your pin safe and don't disclose it to anybody"
- cuspasswords.append(pin)
- cusbalance.append(0)
- balance=100.0
- cusbalance[cusnames.index(name)]=balance
- filewrite(cuspasswords)
- filewrite(cusbalance)
- break
- print ("Sorry, that is a short password")
- return name,pin, balance
- ##Function to check returning customer
- def oldcuscheck():
- name=""
- while name not in cusnames:
- name=raw_input("What is your name?n")
- if name in cusnames:
- username=name
- userpassword=cuspasswords[cusnames.index(name)]
- balance=float(cusbalance[cusnames.index(name)])
- return username, userpassword, balance
- else:
- print ("Sorry %s, It looks like you didn't spell you name correctly or your name is not in our records"%name)
- again=raw_input("would like to type in your name again? (y/n)")
- if again.lower()=='y':
- oldcuscheck()
- else:
- print ("Bye bye, thank you for trying Postbank")
- exit()
- ##This function writes new data into the storage files whenever called upon.
- def filewrite(item):
- if item==cusnames:
- text=open("cusnamefile.txt","w")
- for i in item:
- text.write(i+"n")
- text.close()
- elif item==cuspasswords:
- text=open("cuspassfile.txt", "w")
- for i in item:
- text.write(i+"n")
- text.close()
- elif item==cusbalance:
- text=open("cusbalfile.txt", "w")
- for i in item:
- text.write(str(i)+"n")
- text.close()
- ###This function updates the account balance after a withdraw or deposit transaction
- def balupdate(ind, amount):
- accountnumber=cusnames.index(ind)
- accountbal=float(cusbalance[accountnumber])
- accountbal+=amount
- cusbalance[accountnumber]=accountbal
- text=open("cusbalfile.txt", "w")
- for i in cusbalance:
- text.write(str(i)+"n")
- text.close()
- ###This function deletes an existing account and any data that was stored about it is cleared
- def deleteaccount(name):
- accountnumber=cusnames.index(name)
- del cusnames[accountnumber]
- filewrite(cusnames)
- del cusbalance[accountnumber]
- filewrite(cusbalance)
- del cuspasswords[accountnumber]
- filewrite(cuspasswords)
- return None
- 450693.0
- 6782449.0
- 3525.0
- 6000000.0
- 5532.0
- Loise Njogu
- Moses Njagi
- MakerFuse Limited
- Dad
- Dennis Meyer
- 12345
- 09876
- makerpassword
- thedadpassword
- 234234
- def withdrawcash(self):
- amount=float(raw_input("::n Please enter amount to withdrawn: "))
- self.balance-=amount
- self.working()
- print ("Your new account balance is %.2f" %self.balance)
- print ("::n")
- filestore.balupdate(self.username, -amount)
- self.transact_again()
- class BankApp:
- # ...
- def main(self):
- while True:
- if action == ACTION_QUIT:
- break
- if action == ACTION_WITHDRAW:
- self.handle_withdraw()
- # ...
- def handle_withdraw(self):
- # print welcome
- # input amount
- if self.bank.withdraw(amount):
- # print success
- else:
- # print failure
- namefile=open("cusnamefile.txt", "r")
- # ...
- for line in namefile:
- cusnames.append(line[:-1])
- namefile.close()
- with open("cusnamefile.txt", "r") as namefile:
- for line in namefile:
- cusnames.append(line[:-1])
- cusnames=[]
- with open("cusnamefile.txt") as namefile:
- for line in namefile:
- cusnames.append(line[:-1])
- with open("cusnamefile.txt") as namefile:
- cusnames = [line[:-1] for line in namefile]
- #This is the function that is called at the beginning of the program
- def postbank(): ###
- print ("Welcome to PostBank, We care for youn") ###
- prompt=int(raw_input("""To open a new bank account, Press 1n"""+ ###
- """To access your existing account & transact press 2n""")) ###
- if prompt==1: ###
- cus=BankAccount()#creates a new customer profile ###
- elif prompt==2: ###
- cus=ReturnCustomer()#checks for existing customer ###
- else: ###
- print "You have pressed the wrong key, please try again" ###
- postbank() ###
- ###########################################################################################
- class BankAccount:
- def __init__(self):
- # ...
- print ("Thank you {username}, your account is set up and ready to use,".format(username=self.username)
- + "n" + "a 100 pounds has been credited to your account")
- #############################################################################
- #This is the function that is called at the beginning of the program
- #This is the initial function, it does XYZ process.
- """This is the initial function, it does XYZ process.
- Usage:
- - sumOf(firstNumber, secondNumber)
- For example; the following:
- - sumOf(2, 3) should return 5
- """
- print ("Welcome to PostBank, We care for youn") ###
- prompt=int(raw_input("""To open a new bank account, Press 1n"""+ ###
- """To access your existing account & transact press 2n"""))
- print("Welcome to PostBank, We care for you" + "n")
- prompt = int(raw_input("To open a new bank account, Press 1" + "n"
- + "To access your existing account & transact press 2:" + "n"))
- if prompt==1: ###
- cus=BankAccount()#creates a new customer profile ###
- elif prompt==2: ###
- cus=ReturnCustomer()#checks for existing customer ###
- else: ###
- print "You have pressed the wrong key, please try again" ###
- postbank()
- while(true):
- prompt = int(raw_input("To open a new bank account, Press 1" + "n"
- + "To access your existing account & transact press 2:" + "n"))
- if prompt==1:
- cus = BankAccount() #creates a new customer profile
- elif prompt==2:
- cus = ReturnCustomer() #checks for existing customer
- else:
- print "You have pressed the wrong key, please try again"
- prompts = {
- 1: BankAccount, # Creates a new customer profile
- 2: ReturnCustomer # Checks for existing customer
- }
- while(true):
- prompt = int(raw_input("To open a new bank account, Press 1" + "n"
- + "To access your existing account & transact press 2:" + "n"))
- if prompt in prompts:
- prompts[prompt]()
- else:
- print "You have pressed the wrong key, please try again"
- class BankAccount:
- """Class for a bank account"""
- type="Normal Account"
- def __init__(self):
- ##calls functions in the module filestore
- self.username, self.userpassword, self.balance=filestore.cusaccountcheck()
- print ("Thank you %s, your account is set up and ready to use,n a 100 pounds has been credited to your account" %self.username)
- time.sleep(2)
- self.userfunctions()
- # Class for creating an instance of a new back account and other default bank functions
- class BankAccount:
- def __init__(self):
- # Calls functions in the module filestore
- self.user_name
- self.user_password
- self.balance = file_store.cus_account_check()
- print ("Thank you {username}, your account is set up and ready to use,".format(username=self.username)
- + "n" + "a 100 pounds has been credited to your account")
- self.user_functions()
- import filestore
- import time
- import datetime
- WELCOME_MESSAGE = "Welcome to PostBank, We care for you" + "n"
- def postbank():
- print (WELCOME_MESSAGE)
- prompts = {
- 1: BankAccount, # Creates a new customer profile
- 2: ReturnCustomer # Checks for existing customer
- }
- while True:
- prompt = int(raw_input("To open a new bank account, Press 1" + "n"
- + "To access your existing account & transact press 2:" + "n"))
- if prompt in prompts:
- prompts[prompt]()
- else:
- print "You have pressed the wrong key, please try again"
- # Class for creating an instance of a new back account and other default bank functions
- class BankAccount:
- def __init__(self):
- ##calls functions in the module filestore
- self.user_name
- self.user_password
- self.balance = filestore.cus_account_check()
- print ("Thank you {username}, your account is set up and ready to use,".format(username=self.username)
- + "n" + "a 100 pounds has been credited to your account")
- self.user_functions()
- def user_functions(self):
- print("nnTo access any function below, enter the corresponding key")
- print ("To:" + "n"
- + "Check Balance, press B" + "n"
- + "Deposit cash: press D" + "n"
- + "Withdraw cash, press W" + "n"
- + "Delete account press X" + "n"
- + "Exit service, press E" + "n")
- functions = {
- 'b': self.check_balance,
- 'd': self.deposit_cash,
- 'w': self.withdraw_cash,
- }
- while True:
- answer = raw_input("> ").lower()
- if answer in functions:
- ##passcheck function confirms stored password with user input
- self.pass_check()
- functions[answer]()
- elif answer is 'x':
- print ("{username}, your account is being deleted".format(username=self.username))
- file_store.delete_account(self.username)
- print ("Your account has been successfuly deleted, Goodbye.")
- elif answer is 'e':
- print ("Thank you for using Dot Inc Bank Services")
- print ("Goodbye {username}".format(username=self.username))
- exit()
- else:
- print "No function assigned to this key, please try again"
- def check_balance(self):
- date = datetime.date.today().strftime('%d-%B-%Y')
- print ("Your account balance as at {time} is {balance}").format(time=date, balance=self.balance)
- self.transact_again()
- def withdraw_cash(self):
- amount = float(raw_input("Please enter amount to withdraw:" + "n"))
- self.balance -= amount
- print ("Your new account balance is {balance}".format(balance=self.balance) + "n")
- file_store.balance_update(self.username, -amount)
- self.transact_again()
- def deposit_cash(self):
- amount = float(raw_input("Please enter amount to deposit:" + "n"))
- self.balance += amount
- print ("Your new account balance is {balance}".format(balance=self.balance) + "n")
- file_store.balance_update(self.username, -amount)
- self.transact_again()
- def transact_again(self):
- while True:
- answer = raw_input("Do you want to do another transaction? (y/n)" + "n").lower()
- if ans is 'y':
- self.user_functions()
- elif ans is 'n':
- print ("Thank you for using PostBank we value you. Have a good day.")
- print ("Goodbye {username}").format(username=self.username)
- exit()
- elif ans is not in ['y', 'n']:
- print "Unknown key pressed, please choose either 'N' or 'Y'"
- def pass_check(self):
- # Prompts user for password with every transaction and counterchecks it with stored passwords"
- attempts = 3
- while attempts > 0:
- answer = raw_input("Please type in your password to continue with the transaction:" + "n")
- if answer is self.user_password:
- return True
- else:
- print "That is the wrong password"
- attempts -= 1
- print ("{attempts} more attempt(s) remaining".format(attempts=attempts))
- print ("Account has been frozen due to three wrong password attempts," + "n"
- + "Contact your bank for help.")
- exit()
- class ReturnCustomer():
- def __init__(self):
- self.username
- self.user_password
- self.balance = file_store.old_customer_check()
- self.user_functions()
- postbank()
- "users": {
- "Daynisdot": {
- "password": "python_rox_my_sox.1"
- "balance": 1000000
- "is-locked": false
- }
- "Quill": {
- "password": "featherpen.5"
- "balance": 5.99
- "is-locked": true
- }
- }
Add Comment
Please, Sign In to add comment