Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import sleep
- def valrep(x,change): #function goes through a file and replaces specific values
- with open('users.txt', 'r') as file :
- filedata = file.read()
- for aline in open("users.txt","r").readlines():
- word = aline.split()
- if (word[0] == username) and (word[1] == user_password):
- aline2 = aline.replace(word[x], change)
- filedata = filedata.replace(aline,aline2)
- with open('users.txt', 'w') as file:
- file.write(filedata)
- print("SUCCESS")
- loop = False
- while loop == False:
- username = input("ENTER A VALID USERNAME>>> ")#splits the input into two seperate variables
- user_password = input("ENTER A VALID 4 DIGIT PIN>>> ")
- valnums = '1234567890' #gives a set of valid characters (used later in the program)
- with open("users.txt","r") as user_file:
- for aline in user_file.readlines():
- vals = aline.split()
- if (vals[0] == username) and (vals[1] == user_password):#goes through the text file looking for the valid username and password
- loop2 = False
- while loop2 == False:
- sleep(3.0) #delays the time for menu to appear
- 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
- balance = vals[2] #sets respective part of the file as the balance variable
- print("n"*6)
- option = input("INPUT OPTION PRESS 'Q' TO QUIT>>> ")
- if option == '1':
- print("£",balance)
- sleep(2.0)
- elif option == '2':
- withdrawal = input("SElECT AMOUNT TO WITHDRAW:n £10n £20n £50n £100n OR INPUT AN AMOUNT THAT IS DIVISIBLE BY 10nnnINPUT AMOUNT>>> £")
- if withdrawal%10 == 0:
- print("You selected:£",withdrawal)
- newbalance = float(balance) - float(withdrawal)#sets the newbalance variable
- valrep(2,str(newbalance))
- print("New Balance:£",newbalance)
- sleep(2.0)
- elif option == '3':
- loop3 = True
- while loop3 == True:
- old_pass, new_pass = input("input old PIN and new PIN: ").split(" ")
- if len(new_pass) != 4: #checks if new_pass is 4 characters long
- print("INCORRECT LENGTH")
- elif False in [c in valnums for c in new_pass]: #loops through valnums and compares the variable new_pass to have valid characters
- print("INVALID CHARACTERS")
- elif old_pass == user_password: #checks if old_pass is equal to user_password
- valrep(1,new_pass)
- print("New PIN: ",new_pass)
- loop3 = False
- sleep(2.0)
- elif option.lower() == 'q':
- loop2 = True
- print("Bye", username)
- sleep(5.0)
- else:
- print("INVALID INPUT")
- else:
- print("INVALID INPUT")
- break
- user0001 1234 123.45
- user0002 1234 123.45
- user0003 1234 123.45
- ...
- user9999 1234 123.45
- "INVALID INPUT"
- "INVALID INPUT"
- "INVALID INPUT"
- ...
- ENTER A VALID USERNAME>>> user9999
- ENTER A VALID 4 DIGIT PIN>>> 1234
- ==============================
- WELCOME TO HAYDON BANK, user0001
- ==============================
- WHICH SERVICE DO YOU REQUIRE?
- ==============================
- Option 1: View Balance
- Option 2: Withdrawal
- Option 3: Change PIN
- ==============================
- INPUT OPTION PRESS 'Q' TO QUIT>>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement