So I have the following chunk of code in python which basically opens a text file, makes an array out of the file's text contents (splitting it line by line) and then proceeds to take input from a user and compare that input to each of the terms in the array. Despite the fact that a usersubmitted string is in the array, exactly as it was typed, the program is unable to tell that the two strings are equal. How do I compare the strings? And if this notation is correct, what could possibly be the cause of inequality? I tried substituting "is" for "==" but that didn't work either.
both the input for userinput
is frogeyedpeas
and UserArray[0]
is frogeyedpeas
The file Usernames.txt
frogeyedpeas
vsauce
(there is an additional line that is entirely blank after vsauce)
Code posted below:
Usernames = open('Usernames.txt', 'r+')
UserArray = Usernames.read().split("\n")
userinput = raw_input("Enter Username: ")
passinput = raw_input("Enter Password: ")
i = 0
q = len(UserArray)
while(i < q):
founduser = 0
print userinput, UserArray[i], UserArray #out
if(UserArray[i] == userinput):
founduser = 1
if(PassArray[i] == passinput):
userstatus = i
founduser = 2
i = i + 1