Hi guys. I have a project I am making for a random password generator. I am having an issue with Line 30 with the “break”. It is saying the break is outside of a loop. I’m not sure what to do here or what to put in its place.
Project https://replit.com/@TaylorGraves/Random-Password-Generator?v=1
okay, see how the if statement isn’t indented to fit in the while loop.
instead of this:
# generate password meeting constraints
while True:
pwd = ''
for i in range(pwd_length):
pwd += ''.join(secrets.choice(alphaebet))
if (any(char in special_chars for char in pwd) and
sum(char in digits for char in pwd)>=2):
break
print(pwd)
do this:
# generate password meeting constraints
while True:
pwd = ''
for i in range(pwd_length):
pwd += ''.join(secrets.choice(alphaebet))
if (any(char in special_chars for char in pwd) and
sum(char in digits for char in pwd)>=2):
break
print(pwd)
hope this works!
1 Like
Hi! Thank you for your help! I am not seeing the difference between your code and mine. Maybe my eyes are burning at this point.
okay for the if statement to be read in the while loop, it needs to be indented 1 time. if it is in the for loop, it needs to be indented 2 times to look like this
while True:
pwd = ''
for i in range(pwd_length):
pwd += ''.join(secrets.choice(alphaebet))
if (any(char in special_chars for char in pwd) and
sum(char in digits for char in pwd)>=2):
break
print(pwd)
also, this post should be in code help → python
@TaylorGraves
If your probem has been solved, mark one of the comments as the “Solution” so this post can be closed