Why does this code not work?

Whenever I run the code, if I enter a name thats already in the file it still says that I have created an account and adds it to the file. This isn't what it is supposed to do. If the name is already in the file then it should say that you already have an account and not add your name to the file. If you can... show more Whenever I run the code, if I enter a name thats already in the file it still says that I have created an account and adds it to the file. This isn't what it is supposed to do. If the name is already in the file then it should say that you already have an account and not add your name to the file. If you can please tell me why this doesn't work and how it can be fixed

name = input("Please enter your name: ")
name3 = name[0:3]
print (name3)

names = open("names.txt","a")

if name3 in open("names.txt"):
print("You already have an account")
else:
names.write(name3)
names.write("\n")
print("You have created an account")

names.close()
Update: There is indentations after the if name3 bit and after the else bit. I doesn't show them for some reason.
2 answers 2