Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to rerun script again
#1
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()
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Solved] Trying to rerun a snippet of code paracel 3 1,115 Jul-17-2022, 01:49 PM
Last Post: paracel
  How to rerun the program in a loop with different input? bharaths 3 3,712 Nov-23-2018, 09:36 AM
Last Post: bharaths

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020