Guest User

Untitled

a guest
Feb 2nd, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.50 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 PostBank 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
  301.  
  302. def withdrawcash(self):
  303. amount=float(raw_input("::n Please enter amount to withdrawn: "))
  304. self.balance-=amount
  305. self.working()
  306. print ("Your new account balance is %.2f" %self.balance)
  307. print ("::n")
  308. filestore.balupdate(self.username, -amount)
  309. self.transact_again()
  310.  
  311. class BankApp:
  312. # ...
  313.  
  314. def main(self):
  315. while True:
  316. if action == ACTION_QUIT:
  317. break
  318. if action == ACTION_WITHDRAW:
  319. self.handle_withdraw()
  320. # ...
  321.  
  322. def handle_withdraw(self):
  323. # print welcome
  324.  
  325. # input amount
  326.  
  327. if self.bank.withdraw(amount):
  328. # print success
  329. else:
  330. # print failure
  331.  
  332. namefile=open("cusnamefile.txt", "r")
  333. # ...
  334. for line in namefile:
  335. cusnames.append(line[:-1])
  336. namefile.close()
  337.  
  338. with open("cusnamefile.txt", "r") as namefile:
  339. for line in namefile:
  340. cusnames.append(line[:-1])
  341.  
  342. cusnames=[]
  343.  
  344. with open("cusnamefile.txt") as namefile:
  345. for line in namefile:
  346. cusnames.append(line[:-1])
  347.  
  348. with open("cusnamefile.txt") as namefile:
  349. cusnames = [line[:-1] for line in namefile]
  350.  
  351. #This is the function that is called at the beginning of the program
  352. def postbank(): ###
  353. print ("Welcome to PostBank, We care for youn") ###
  354. prompt=int(raw_input("""To open a new bank account, Press 1n"""+ ###
  355. """To access your existing account & transact press 2n""")) ###
  356. if prompt==1: ###
  357. cus=BankAccount()#creates a new customer profile ###
  358. elif prompt==2: ###
  359. cus=ReturnCustomer()#checks for existing customer ###
  360. else: ###
  361. print "You have pressed the wrong key, please try again" ###
  362. postbank() ###
  363. ###########################################################################################
  364.  
  365. class BankAccount:
  366. def __init__(self):
  367. # ...
  368. print ("Thank you {username}, your account is set up and ready to use,".format(username=self.username)
  369. + "n" + "a 100 pounds has been credited to your account")
  370.  
  371. #############################################################################
  372. #This is the function that is called at the beginning of the program
  373.  
  374. #This is the initial function, it does XYZ process.
  375.  
  376. """This is the initial function, it does XYZ process.
  377. Usage:
  378. - sumOf(firstNumber, secondNumber)
  379. For example; the following:
  380. - sumOf(2, 3) should return 5
  381. """
  382.  
  383. print ("Welcome to PostBank, We care for youn") ###
  384. prompt=int(raw_input("""To open a new bank account, Press 1n"""+ ###
  385. """To access your existing account & transact press 2n"""))
  386.  
  387. print("Welcome to PostBank, We care for you" + "n")
  388. prompt = int(raw_input("To open a new bank account, Press 1" + "n"
  389. + "To access your existing account & transact press 2:" + "n"))
  390.  
  391. if prompt==1: ###
  392. cus=BankAccount()#creates a new customer profile ###
  393. elif prompt==2: ###
  394. cus=ReturnCustomer()#checks for existing customer ###
  395. else: ###
  396. print "You have pressed the wrong key, please try again" ###
  397. postbank()
  398.  
  399. while(true):
  400. prompt = int(raw_input("To open a new bank account, Press 1" + "n"
  401. + "To access your existing account & transact press 2:" + "n"))
  402. if prompt==1:
  403. cus = BankAccount() #creates a new customer profile
  404. elif prompt==2:
  405. cus = ReturnCustomer() #checks for existing customer
  406. else:
  407. print "You have pressed the wrong key, please try again"
  408.  
  409. prompts = {
  410. 1: BankAccount, # Creates a new customer profile
  411. 2: ReturnCustomer # Checks for existing customer
  412. }
  413. while(true):
  414. prompt = int(raw_input("To open a new bank account, Press 1" + "n"
  415. + "To access your existing account & transact press 2:" + "n"))
  416. if prompt in prompts:
  417. prompts[prompt]()
  418. else:
  419. print "You have pressed the wrong key, please try again"
  420.  
  421. class BankAccount:
  422. """Class for a bank account"""
  423. type="Normal Account"
  424. def __init__(self):
  425. ##calls functions in the module filestore
  426. self.username, self.userpassword, self.balance=filestore.cusaccountcheck()
  427. 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)
  428. time.sleep(2)
  429. self.userfunctions()
  430.  
  431. # Class for creating an instance of a new back account and other default bank functions
  432. class BankAccount:
  433. def __init__(self):
  434. # Calls functions in the module filestore
  435. self.user_name
  436. self.user_password
  437. self.balance = file_store.cus_account_check()
  438. print ("Thank you {username}, your account is set up and ready to use,".format(username=self.username)
  439. + "n" + "a 100 pounds has been credited to your account")
  440. self.user_functions()
  441.  
  442. import filestore
  443. import time
  444. import datetime
  445.  
  446. WELCOME_MESSAGE = "Welcome to PostBank, We care for you" + "n"
  447. def postbank():
  448. print (WELCOME_MESSAGE)
  449. prompts = {
  450. 1: BankAccount, # Creates a new customer profile
  451. 2: ReturnCustomer # Checks for existing customer
  452. }
  453. while True:
  454. prompt = int(raw_input("To open a new bank account, Press 1" + "n"
  455. + "To access your existing account & transact press 2:" + "n"))
  456. if prompt in prompts:
  457. prompts[prompt]()
  458. else:
  459. print "You have pressed the wrong key, please try again"
  460.  
  461.  
  462. # Class for creating an instance of a new back account and other default bank functions
  463. class BankAccount:
  464. def __init__(self):
  465. ##calls functions in the module filestore
  466. self.user_name
  467. self.user_password
  468. self.balance = filestore.cus_account_check()
  469. print ("Thank you {username}, your account is set up and ready to use,".format(username=self.username)
  470. + "n" + "a 100 pounds has been credited to your account")
  471. self.user_functions()
  472.  
  473.  
  474. def user_functions(self):
  475. print("nnTo access any function below, enter the corresponding key")
  476. print ("To:" + "n"
  477. + "Check Balance, press B" + "n"
  478. + "Deposit cash: press D" + "n"
  479. + "Withdraw cash, press W" + "n"
  480. + "Delete account press X" + "n"
  481. + "Exit service, press E" + "n")
  482.  
  483. functions = {
  484. 'b': self.check_balance,
  485. 'd': self.deposit_cash,
  486. 'w': self.withdraw_cash,
  487. }
  488. while True:
  489. answer = raw_input("> ").lower()
  490. if answer in functions:
  491. ##passcheck function confirms stored password with user input
  492. self.pass_check()
  493. functions[answer]()
  494. elif answer is 'x':
  495. print ("{username}, your account is being deleted".format(username=self.username))
  496. file_store.delete_account(self.username)
  497. print ("Your account has been successfuly deleted, Goodbye.")
  498. elif answer is 'e':
  499. print ("Thank you for using Dot Inc Bank Services")
  500. print ("Goodbye {username}".format(username=self.username))
  501. exit()
  502. else:
  503. print "No function assigned to this key, please try again"
  504.  
  505. def check_balance(self):
  506. date = datetime.date.today().strftime('%d-%B-%Y')
  507. print ("Your account balance as at {time} is {balance}").format(time=date, balance=self.balance)
  508. self.transact_again()
  509.  
  510. def withdraw_cash(self):
  511. amount = float(raw_input("Please enter amount to withdraw:" + "n"))
  512. self.balance -= amount
  513. print ("Your new account balance is {balance}".format(balance=self.balance) + "n")
  514. file_store.balance_update(self.username, -amount)
  515. self.transact_again()
  516.  
  517. def deposit_cash(self):
  518. amount = float(raw_input("Please enter amount to deposit:" + "n"))
  519. self.balance += amount
  520. print ("Your new account balance is {balance}".format(balance=self.balance) + "n")
  521. file_store.balance_update(self.username, -amount)
  522. self.transact_again()
  523.  
  524.  
  525.  
  526. def transact_again(self):
  527. while True:
  528. answer = raw_input("Do you want to do another transaction? (y/n)" + "n").lower()
  529. if ans is 'y':
  530. self.user_functions()
  531. elif ans is 'n':
  532. print ("Thank you for using PostBank we value you. Have a good day.")
  533. print ("Goodbye {username}").format(username=self.username)
  534. exit()
  535. elif ans is not in ['y', 'n']:
  536. print "Unknown key pressed, please choose either 'N' or 'Y'"
  537.  
  538.  
  539. def pass_check(self):
  540. # Prompts user for password with every transaction and counterchecks it with stored passwords"
  541. attempts = 3
  542. while attempts > 0:
  543. answer = raw_input("Please type in your password to continue with the transaction:" + "n")
  544. if answer is self.user_password:
  545. return True
  546. else:
  547. print "That is the wrong password"
  548. attempts -= 1
  549. print ("{attempts} more attempt(s) remaining".format(attempts=attempts))
  550.  
  551. print ("Account has been frozen due to three wrong password attempts," + "n"
  552. + "Contact your bank for help.")
  553. exit()
  554.  
  555.  
  556. class ReturnCustomer():
  557. def __init__(self):
  558. self.username
  559. self.user_password
  560. self.balance = file_store.old_customer_check()
  561. self.user_functions()
  562.  
  563. postbank()
  564.  
  565. "users": {
  566. "Daynisdot": {
  567. "password": "python_rox_my_sox.1"
  568. "balance": 1000000
  569. "is-locked": false
  570. }
  571. "Quill": {
  572. "password": "featherpen.5"
  573. "balance": 5.99
  574. "is-locked": true
  575. }
  576. }
Add Comment
Please, Sign In to add comment