profound.donut
profound.donut

Reputation: 33

Issue with conditional statement on external python file

I created this script that could be used as a login, and then created an external text file that has the data 1234 in it, this is attempting to compare the data from the file, but outputs that the two values are different, even though they are the same. Thanks In advance to any help you can give me, the code I used is below:

getUsrName = input("Enter username: ")
file = open("documents/pytho/login/cdat.txt", "r")
lines = file.readlines()
recievedUsrName = lines[1]
file.close()
print(getUsrName)
print(recievedUsrName)
if recievedUsrName == getUsrName:
    print("hello")
elif getUsrName != recievedUsrName:
    print("bye")
else:

Upvotes: -1

Views: 45

Answers (1)

zipa
zipa

Reputation: 27889

Try it like:

if recievedUsrName.strip() == getUsrName:
    ...

It must be the trailing newline.

Upvotes: 0

Related Questions