Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f=open("UsernamePasswords.txt","r")#opens text file
- usernamePasswords=[]#creates new list
- for line in f:#for each line in the textfile
- line=line.strip("\n")#strip the /n in the line
- usernamePasswords.append(line.split())#append the line and break between the space
- username=input("Enter your username: ")#asks user for username
- found=False#found is false
- uPlength=len(usernamePasswords)#length of list
- for i in range(uPlength):#for each index in the range of the lists length
- if username == usernamePasswords[i][0]:#if the username is equal to the one in the list
- print("Password =",usernamePasswords[i][1])#prints out the password
- found=True#found is true
- if found == False:#if its not found
- print("Username not found")#prints out that the username was not found
- f.close()#closes the text file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement