Python Forum
cant figure this out - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: cant figure this out (/thread-22848.html)



cant figure this out - louiecooper - Nov-29-2019

x = input("do you have an account yes or no?")
if x != ("yes"):
   quit()
else:
    x = input("what is your username")
    y = input("what is your password")

file=open("usernamepassword.txt","w+")
file.write("Ben McNeill")
file.write("bartisnoob")
file.close()

import random
with open("usernamepassword.txt") as f:
    lines = f.readlines()
    print(random.choice(lines))

if x + y == ("usernamepassword.txt"):
   print("your password and username are correct")
else:
   quit()
It wont compare the file handling to what the input is, any help would be nice.


RE: cant figure this out - ThomasL - Nov-29-2019

if x + y == ("usernamepassword.txt")
if you enter "username" for username and "password.txt" for password than this condition would be True:
otherwise it doesn´t make any sense at all.
You need to compare the contents of variable lines after reading the file with the contents of x and y.