0

Basically, I'm attempting to make a password generator. I wanted to make it a bit higher quality than what some of the tutorials I watched suggested, so I tried to allow some user input; I wanted the user to be able to type in a number and let them decide how long they want it to be. So I used an "if statement" alongside "try" and "except" in the event that a user writes a letter or any character other than a number. The code looks as follows:

print("How long do you want your password to be?")
pass_length = input()
if pass_length:
    try:
        print(str(get_random_string(int(pass_length))))
    except ValueError:
        while pass_length:
            print("Error: Please input a whole number integer value.")
            print("=============================================================")
            print("How long do you want your password to be?")
            pass_length = input()
            if pass_length == int():
                break

Now, if the user inputs a number, the program runs smoothly and dispenses a random string. the problem is that for reasons that are probably very obvious to you, dear reader, is whenever I incur the wrath of the except conditions, even if the user inputs a digit, it'll still return the error message. Sorry if I leave important or otherwise significant information out, I'm very daft as you can tell.

Thanks!

0 Answers0