# format: user, password a_file = open("User_List_&_Passwords.txt", "r") # read the file into into a list lines lines = a_file.readlines() # we don't need a_file anymore a_file.close() # init lists Namelist = [] Passwordlist = [] # iterate through the lines list for line in lines: # remove whitespace, if nothing is left it's a blank line # we skip those (this could be improved to also skip/error # on incomplete or invalid password lines) if line.strip() == "": continue # split at the "," as_list = line.split(",") # remove possible trailing/leading whitespace and add to list Namelist.append(as_list[0].strip()) Passwordlist.append(as_list[1].strip()) # no changes from me in the code below... count = 0 SearchName = input("Please enter user name:") if SearchName not in Namelist: while SearchName not in Namelist and count != 3: print(SearchName, "is incorrect") SearchName = input("Please enter user name:") count = count + 1 else: print(SearchName, "Correct user name") print(Namelist.index(SearchName)) count1 = 0 SearchPassword = input("Please enter your password:") if SearchPassword not in Passwordlist: while SearchPassword not in Passwordlist and count1 != 3: print(SearchPassword, "Password incorrect") SearchPassword = input("Please enter correct password:") count1 = count1 + 1 else: print(SearchPassword, "Correct password")