I have this code:
while True:
uName = []
uPassword = []
maxLengthList = 1
maxPassList = 1
acceptEnt = ["YES", "yes", "Y", "y"]
denyEnt = ["NO", "no", "N", "y"]
while len(uName) < maxLengthList:
item = raw_input("Create a username: ")
uName.append(item)
checkU = raw_input("Is %s correct? " % uName)
if checkU in acceptEnt:
while len(uPassword) < maxPassList:
pw = raw_input("Create a password: ")
uPassword.append(pw)
checkP = raw_input("Is %s correct? " % uPassword)
if checkP in acceptEnt:
print "%s logging in..." % uName
else:
if checkU in denyEnt or checkP in denyEnt:
print "Error"
break
that is supposed to have a user create a username, and password, then it passes to this:
done = True
while done == True:
sys.stdout.write('\rLoading')
time.sleep(0.11)
sys.stdout.write('\rLoading. ')
time.sleep(1)
sys.stdout.write('\rLoading.. ')
time.sleep(2)
sys.stdout.write('\rLoading... ')
time.sleep(1)
sys.stdout.write('\rLoading.... ')
time.sleep(0.39)
sys.stdout.write('\rLoading..... ')
time.sleep(0.19)
sys.stdout.write('\rLoading...... ')
time.sleep(0.25)
done = False
sys.stdout.write('\rInitializing')
time.sleep(3)
sys.stdout.write('\rHello, %s' % uName)
time.sleep(1.5)
which only simulates a loading operation. I need it to not pass to that code block until a user enters both a username and password, but even if the user inputs "no" when asking if %s is correct, it passes to the next code.
I am trying to get it to stick to the account creation until a real input is entered, and when "no" is input, then throw the user back to the previous creation screen. I don't want them to be able to bypass that part at all, which is what they can do.
UPDATE:
I ended up changing it to a boolean, seemed quicker to me though I plan on cleaning the code up a little bit.
entry = True
while entry == True:
uName = []
uPassword = []
maxLengthList = 1
maxPassList = 1
acceptEnt = ["YES", "yes", "Y", "y"]
denyEnt = ["NO", "no", "N", "y"]
while len(uName) < maxLengthList:
item = raw_input("Create a username: ")
uName.append(item)
checkU = raw_input("Is %s correct? " % uName)
if checkU in acceptEnt:
while len(uPassword) < maxPassList:
pw = raw_input("Create a password: ")
uPassword.append(pw)
checkP = raw_input("Is %s correct? " % uPassword)
if checkP in acceptEnt:
print "%s logging in..." % uName
entry = False
break
else:
print "pw wrong test"
else:
print "uname wrong test"
break
This seems to work for the time being though I will most definitely visit it again as I look for alternatives such as the ones mentioned here.