Python Forum

Full Version: How to rerun script again
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.

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()
I would change your while loops into an if/elif chain. Then put it all into a while loop. Keep the break for valid login, break on exit, and stay in the loop for bad login or new account.
(Apr-29-2019, 08:53 PM)ichabod801 Wrote: [ -> ]I would change your while loops into an if/elif chain. Then put it all into a while loop. Keep the break for valid login, break on exit, and stay in the loop for bad login or new account.
thanks, I managed to fix it finally! Big Grin