//this asked a fresh user for log in details and then appends it to the file
while choice == '1':
username = input('enter a name: ')
if username == '':
print ('user name cant be blank')
else:
print ('hello', username,'welcome to the quiz')
password = input('please enter a password that is 4 characters long: ')
while (len(password)) < 4:
password = input('please enter a password that is 4 characters long: ')
else:
f = open("logininfo", "a")
f.write('---------' '\n')
f.write(username '\n')
f.write(password '\n')
f.write('---------' '\n')
f.close()
print('welcome you may now begin')
choice=choice choice choice
//this is for when a user wants to log in and the system checks in the file for already inputted data
while choice == '2':
print ('enter your log in details')
username = input('username:')
password = input('password:')
if username in logininfo:
print ("That user already exsist")
else:
f = open('logininfo','r')
if username in ('logininfo'):
print('welcome')
else:
print ('no entry')
CodePudding user response:
Try like this:
with open("logininfo", "r") as f:
all_text = f.read()
Now find the username in the variable string 'all_text' with if statement