Apr-29-2019, 07:40 PM
I have finally made a full login system but the issue is that now when I enter option b and fill out my process, it would stop instead of going through the whole script again. How can I rerun the script? I tried putting all the while loops into a big loop but if I break, it only breaks the nested loop in Option A instead of the entire loop and adding more breaks mess up the else that's part of option A. Return also doesn't work since it only works in functions and loops don't work in functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
logged_in = False attempts = 0 username_s = [] password_s = [] with open ( 'Account_Data.txt' , 'r' ) as file : for line in file : username, password = line.strip().split( ',' ) username_s.append( str (username)) password_s.append( str (password)) enter_option = input ( 'A,B,C ' ) while enter_option = = 'A' : enter_name = input ( 'ENTER NAME: ' ) enter_password = input ( 'ENTER PASSWORD: ' ) if enter_name in username_s and enter_password = = password_s[username_s.index(enter_name)]: logged_in = True break else : print ( 'ERROR: TRY AGAIN ' ) continue while enter_option = = 'B' : enter_new_name = input ( 'ENTER NEW NAME: ' ) enter_new_pword = input ( 'ENTER NEW PASSWORD: ' ) with open ( 'Account_Data.txt' , 'a' ) as file : file .write(enter_new_name + ',' + enter_new_pword + '\n' ) while enter_option = = 'C' : print ( 'EXIT' ) exit() if logged_in = = True : print ( 'Hello' ) file .close() |