Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. from time import sleep
  2.  
  3. def valrep(x,change): #function goes through a file and replaces specific values
  4. with open('users.txt', 'r') as file :
  5. filedata = file.read()
  6. for aline in open("users.txt","r").readlines():
  7. word = aline.split()
  8. if (word[0] == username) and (word[1] == user_password):
  9. aline2 = aline.replace(word[x], change)
  10. filedata = filedata.replace(aline,aline2)
  11. with open('users.txt', 'w') as file:
  12. file.write(filedata)
  13. print("SUCCESS")
  14.  
  15. loop = False
  16. while loop == False:
  17. username = input("ENTER A VALID USERNAME>>> ")#splits the input into two seperate variables
  18. user_password = input("ENTER A VALID 4 DIGIT PIN>>> ")
  19. valnums = '1234567890' #gives a set of valid characters (used later in the program)
  20. with open("users.txt","r") as user_file:
  21. for aline in user_file.readlines():
  22. vals = aline.split()
  23. if (vals[0] == username) and (vals[1] == user_password):#goes through the text file looking for the valid username and password
  24. loop2 = False
  25. while loop2 == False:
  26. sleep(3.0) #delays the time for menu to appear
  27. print("n"*300,"="*30,"nnnWELCOME TO HAYDON BANK, {} nnn".format(username),"="*30,"n WHICH SERVICE DO YOU REQUIRE?n","="*30,"nnn Option 1: View Balancenn Option 2: Withdrawalnn Option 3: Change PINnnn","="*30,"n")#this is the menu
  28. balance = vals[2] #sets respective part of the file as the balance variable
  29. print("n"*6)
  30. option = input("INPUT OPTION PRESS 'Q' TO QUIT>>> ")
  31. if option == '1':
  32. print("£",balance)
  33. sleep(2.0)
  34. elif option == '2':
  35. withdrawal = input("SElECT AMOUNT TO WITHDRAW:n £10n £20n £50n £100n OR INPUT AN AMOUNT THAT IS DIVISIBLE BY 10nnnINPUT AMOUNT>>> £")
  36. if withdrawal%10 == 0:
  37. print("You selected:£",withdrawal)
  38. newbalance = float(balance) - float(withdrawal)#sets the newbalance variable
  39. valrep(2,str(newbalance))
  40. print("New Balance:£",newbalance)
  41. sleep(2.0)
  42. elif option == '3':
  43. loop3 = True
  44. while loop3 == True:
  45. old_pass, new_pass = input("input old PIN and new PIN: ").split(" ")
  46. if len(new_pass) != 4: #checks if new_pass is 4 characters long
  47. print("INCORRECT LENGTH")
  48. elif False in [c in valnums for c in new_pass]: #loops through valnums and compares the variable new_pass to have valid characters
  49. print("INVALID CHARACTERS")
  50. elif old_pass == user_password: #checks if old_pass is equal to user_password
  51. valrep(1,new_pass)
  52. print("New PIN: ",new_pass)
  53. loop3 = False
  54. sleep(2.0)
  55. elif option.lower() == 'q':
  56. loop2 = True
  57. print("Bye", username)
  58. sleep(5.0)
  59. else:
  60. print("INVALID INPUT")
  61. else:
  62. print("INVALID INPUT")
  63. break
  64.  
  65. user0001 1234 123.45
  66. user0002 1234 123.45
  67. user0003 1234 123.45
  68. ...
  69. user9999 1234 123.45
  70.  
  71. "INVALID INPUT"
  72. "INVALID INPUT"
  73. "INVALID INPUT"
  74. ...
  75.  
  76. ENTER A VALID USERNAME>>> user9999
  77. ENTER A VALID 4 DIGIT PIN>>> 1234
  78.  
  79. ==============================
  80.  
  81.  
  82. WELCOME TO HAYDON BANK, user0001
  83.  
  84.  
  85. ==============================
  86. WHICH SERVICE DO YOU REQUIRE?
  87. ==============================
  88.  
  89.  
  90. Option 1: View Balance
  91.  
  92. Option 2: Withdrawal
  93.  
  94. Option 3: Change PIN
  95.  
  96.  
  97. ==============================
  98.  
  99.  
  100.  
  101.  
  102.  
  103. INPUT OPTION PRESS 'Q' TO QUIT>>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement