Advertisement
Guest User

Untitled

a guest
Sep 5th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.01 KB | None | 0 0
  1. import filestore
  2. import time
  3. import datetime
  4.  
  5.  
  6.  
  7. #############################################################################
  8. #This is the function that is called at the beginning of the program
  9. def postbank(): ###
  10. print ("Welcome to PostBank, We care for youn") ###
  11. prompt=int(raw_input("""To open a new bank account, Press 1n"""+ ###
  12. """To access your existing account & transact press 2n""")) ###
  13. if prompt==1: ###
  14. cus=BankAccount()#creates a new customer profile ###
  15. elif prompt==2: ###
  16. cus=ReturnCustomer()#checks for existing customer ###
  17. else: ###
  18. print "You have pressed the wrong key, please try again" ###
  19. postbank() ###
  20. ###########################################################################################
  21.  
  22.  
  23.  
  24.  
  25. ##class for creating an instance of a new back account and other default bank functions
  26. class BankAccount:
  27. """Class for a bank account"""
  28. type="Normal Account"
  29. def __init__(self):
  30. ##calls functions in the module filestore
  31. self.username, self.userpassword, self.balance=filestore.cusaccountcheck()
  32. 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)
  33. time.sleep(2)
  34. self.userfunctions()
  35.  
  36.  
  37.  
  38. def userfunctions(self):
  39. print("nnTo access any function below, enter the corresponding key")
  40. print ("""To:
  41. check Balance, press B.
  42. deposit cash, press D.
  43. withdraw cash, press W.
  44. Delete account press X.
  45. exit service, press En
  46. :"""),
  47. ans=raw_input("").lower()
  48. if ans=='b':
  49. ##passcheck function confirms stored password with user input
  50. self.passcheck()
  51. self.checkbalance()
  52. elif ans=='d':
  53. self.passcheck()
  54. self.depositcash()
  55. elif ans=='w':
  56. self.passcheck()
  57. self.withdrawcash()
  58. elif ans=='x':
  59. print ("%s, your account is being deleted"%self.username)
  60. time.sleep(1)
  61. print ("Minions at work")
  62. time.sleep(1)
  63. filestore.deleteaccount(self.username)
  64. print ("Your account has been successfuly deleted, goodbye")
  65. elif ans=='e':
  66. print ("Thank you for using Dot Inc Bank Services")
  67. time.sleep(1)
  68. print ("Goodbye %s" %self.username)
  69. exit()
  70.  
  71. else:
  72. print "No function assigned to this key, please try again"
  73. self.userfunctions()
  74.  
  75. def checkbalance(self):
  76. date=datetime.date.today()
  77. date=date.strftime('%d-%B-%Y')
  78. self.working()
  79. print ("Your account balance as at {} is {}").format(date, self.balance)
  80. self.transact_again()
  81.  
  82. def withdrawcash(self):
  83. amount=float(raw_input("::n Please enter amount to withdrawn: "))
  84. self.balance-=amount
  85. self.working()
  86. print ("Your new account balance is %.2f" %self.balance)
  87. print ("::n")
  88. filestore.balupdate(self.username, -amount)
  89. self.transact_again()
  90.  
  91. def depositcash(self):
  92. amount=float(raw_input("::nPlease enter amount to be depositedn: "))
  93. self.balance+=amount
  94. self.working()
  95. print ("Your new account balance is %.2f" %self.balance)
  96. print ("::n")
  97. filestore.balupdate(self.username, amount)
  98. self.transact_again()
  99.  
  100.  
  101.  
  102. def transact_again(self):
  103. ans=raw_input("Do you want to do any other transaction? (y/n)n").lower()
  104. self.working()
  105. if ans=='y':
  106. self.userfunctions()
  107. elif ans=='n':
  108. print ("Thank you for using PostBank we value you. Have a good day")
  109. time.sleep(1)
  110. print ("Goodbye {}").format(self.username)
  111. exit()
  112. elif ans!='y' and ans!='n':
  113. print "Unknown key pressed, please choose either 'N' or 'Y'"
  114. self.transact_again()
  115.  
  116.  
  117. def working(self):
  118. print("working"),
  119. time.sleep(1)
  120. print ("..")
  121. time.sleep(1)
  122. print("..")
  123. time.sleep(1)
  124.  
  125.  
  126. def passcheck(self):
  127. """prompts user for password with every transaction and counterchecks it with stored passwords"""
  128. b=3
  129. while b>0:
  130. ans=raw_input("Please type in your password to continue with the transactionn: ")
  131. if ans==self.userpassword:
  132. return True
  133.  
  134.  
  135. else:
  136. print "That is the wrong password"
  137. b-=1
  138. print ("%d more attempt(s) remaining" %b)
  139.  
  140. print ("Account has been freezed due to three wrong password attempts,n contact your bank for help, bye bye")
  141. time.sleep(1)
  142. print ("...")
  143. time.sleep(1)
  144. print("...")
  145. time.sleep(1)
  146.  
  147. exit()
  148.  
  149.  
  150. class ReturnCustomer(BankAccount):
  151. type="Normal Account"
  152. def __init__(self):
  153. self.username, self.userpassword, self.balance=filestore.oldcuscheck()
  154. self.userfunctions()
  155.  
  156. postbank() ##calling the function to run the program
  157.  
  158. ##creating empty lists everytime the program is initialized
  159. cusnames=[]
  160. cuspasswords=[]
  161. cusbalance=[]
  162.  
  163. ##opening the storage files to collect old customer data
  164. namefile=open("cusnamefile.txt", "r")
  165. passfile=open("cuspassfile.txt", "r")
  166. balfile=open("cusbalfile.txt", "r")
  167.  
  168. ##populate the empty lists with data from storage files
  169. ##check list of customer names
  170. for line in namefile:
  171. cusnames.append(line[:-1])
  172. namefile.close()
  173.  
  174. ##check list of customer passwords
  175. for line in passfile:
  176. cuspasswords.append(line[:-1])
  177. passfile.close()
  178.  
  179. ##check list of customer balances
  180. for line in balfile:
  181. cusbalance.append(line[:-1])
  182. balfile.close()
  183.  
  184.  
  185. ##function creates a new user
  186. def cusaccountcheck():
  187. name=""
  188. pin=""
  189.  
  190. while name not in cusnames and len(name)<3:
  191. name=raw_input("Please type in your name for this new bank accountn")
  192. if name not in cusnames:
  193. cusnames.append(name)
  194. filewrite(cusnames)
  195. break
  196. print("Sorry, that user name is already in use")
  197. ans=raw_input("Are you already a member at this bank? (y/n)n")
  198. if ans.lower()=='y':
  199. oldcuscheck()
  200. else:
  201. cusaccountcheck()
  202.  
  203. while len(pin)<4:
  204. pin=raw_input("Please assign a password to this account, pin should be at least 5 charactersn")
  205. if len(pin)>4:
  206. print "your pin has been successfully saved"
  207. print "Remember to always keep your pin safe and don't disclose it to anybody"
  208. cuspasswords.append(pin)
  209. cusbalance.append(0)
  210. balance=100.0
  211. cusbalance[cusnames.index(name)]=balance
  212. filewrite(cuspasswords)
  213. filewrite(cusbalance)
  214. break
  215.  
  216. print ("Sorry, that is a short password")
  217.  
  218. return name,pin, balance
  219.  
  220. ##Function to check returning customer
  221. def oldcuscheck():
  222. name=""
  223. while name not in cusnames:
  224. name=raw_input("What is your name?n")
  225. if name in cusnames:
  226. username=name
  227. userpassword=cuspasswords[cusnames.index(name)]
  228. balance=float(cusbalance[cusnames.index(name)])
  229. return username, userpassword, balance
  230. else:
  231. print ("Sorry %s, It looks like you didn't spell you name correctly or your name is not in our records"%name)
  232. again=raw_input("would like to type in your name again? (y/n)")
  233. if again.lower()=='y':
  234. oldcuscheck()
  235. else:
  236. print ("Bye bye, thank you for trying Postbank")
  237. exit()
  238.  
  239.  
  240.  
  241.  
  242. ##This function writes new data into the storage files whenever called upon.
  243. def filewrite(item):
  244. if item==cusnames:
  245. text=open("cusnamefile.txt","w")
  246. for i in item:
  247. text.write(i+"n")
  248. text.close()
  249.  
  250. elif item==cuspasswords:
  251. text=open("cuspassfile.txt", "w")
  252. for i in item:
  253. text.write(i+"n")
  254. text.close()
  255.  
  256. elif item==cusbalance:
  257. text=open("cusbalfile.txt", "w")
  258. for i in item:
  259. text.write(str(i)+"n")
  260. text.close()
  261.  
  262. ###This function updates the account balance after a withdraw or deposit transaction
  263. def balupdate(ind, amount):
  264. accountnumber=cusnames.index(ind)
  265. accountbal=float(cusbalance[accountnumber])
  266. accountbal+=amount
  267. cusbalance[accountnumber]=accountbal
  268. text=open("cusbalfile.txt", "w")
  269. for i in cusbalance:
  270. text.write(str(i)+"n")
  271. text.close()
  272.  
  273. ###This function deletes an existing account and any data that was stored about it is cleared
  274. def deleteaccount(name):
  275. accountnumber=cusnames.index(name)
  276. del cusnames[accountnumber]
  277. filewrite(cusnames)
  278. del cusbalance[accountnumber]
  279. filewrite(cusbalance)
  280. del cuspasswords[accountnumber]
  281. filewrite(cuspasswords)
  282. return None
  283.  
  284. 450693.0
  285. 6782449.0
  286. 3525.0
  287. 6000000.0
  288. 5532.0
  289.  
  290. Loise Njogu
  291. Moses Njagi
  292. MakerFuse Limited
  293. Dad
  294. Dennis Meyer
  295.  
  296. 12345
  297. 09876
  298. makerpassword
  299. thedadpassword
  300. 234234
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement