Familiar example

Report a typo

Getting back to the example with password generation, here's a bugged version of the program one more time:

def password_generator(length):
    chars = string.ascii_letters + string.digits + string.punctuation
    confusing_chars = ('O', '0', '1', 'l')
    password = ''
    while not len(password) == length:
        char = random.choice(chars)
        if char in confusing_chars:
            password += char
    return password

Start the debugging mode, run this function and press "Step" seven times. You will find debugger analyzing lines in the random module. But you know that the actual error is not there: which button will you press to get to the next line of your function (i.e. if char in confusing chars) and not to waste time checking the code of the module?

Do not forget to import the modules string and random in the first place.
Select one option from the list
___

Create a free account to access the full topic