Here I have some code I've been working on (Python 3.4) and I can't figure out how to get the program to restart after the else
statement. I know that there is no goto
statement.
I have tried messing about by putting the if
statement in a while true
loop but it just looped the print
line and printed the output over and over again
import random
import string
PassGen = ""
length = int(input("how many characters would you like your password to have 8-15? "))
if 8 <= length <=15:
while len(PassGen) != length:
Num1 = random.choice(string.ascii_uppercase)
Num2 = random.choice(string.ascii_lowercase)
Num3 = random.choice(string.digits)
everything = [Num1, Num2, Num3]
PassGen += random.choice(everything)
print (PassGen)
else:
print ("that is an incorrect value")
At the moment it works perfectly fine by taking an input from the user then seeing if the input is between 8-15. If so, it makes a password with the inner while
loop. Otherwise, it prints the incorrect value.