First password generator in Python This is my first project using Python. I made a simple password generator that checks user input. How can I improve it?
import random
def password_generator():
    password = []
    letters = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;, &quot;g&quot;, &quot;h&quot;, &quot;i&quot;, &quot;j&quot;, &quot;k&quot;, &quot;l&quot;, &quot;m&quot;, &quot;n&quot;, &quot;o&quot;, &quot;p&quot;, &quot;q&quot;, &quot;r&quot;, &quot;s&quot;, &quot;t&quot;, &quot;u&quot;,
               &quot;v&quot;, &quot;w&quot;, &quot;x&quot;, &quot;y&quot;, &quot;z&quot;]
    password_length = 0
    password_numbers = []
    password_letters = []
    # Input the length of the password
    while True:
        password_length_input = input(&quot;Choose the length of your password with numbers between 6 and 15:\n&quot;)
        if not password_length_input.isnumeric():
            print(f&quot;{password_length_input} is not a number, try again:&quot;)
            continue
        else:
            password_length = int(password_length_input)
            print(f&quot;Password length: {password_length}&quot;)
        if 6 &lt;= password_length &lt;= 15:
            break
        else:
            print(&quot;The password must be between 6 and 15 characters, try again:&quot;)
            continue
    # Input the amount of numbers in password
    while True:
        password_numbers_input = \
            input(f&quot;Choose the amount of numbers you want in your password, max {password_length}\n&quot;)
        if not password_numbers_input.isnumeric():
            print(f&quot;{password_numbers_input} is not a number try again&quot;)
            continue
        elif int(password_numbers_input) &gt; password_length:
            password_numbers = 0
            print(f&quot;The value is too high, choose maximum {password_length} numbers&quot;)
            continue
        else:
            password_numbers = int(password_numbers_input)
            print(f&quot;Password numbers: {password_numbers}&quot;)
            for number in range(0,password_numbers):
                password.append(random.randrange(0,9))
            break
    # Check for numbers and letters in password
    while True:
        if password_numbers == password_length:
            print(f&quot;The password will be only {password_numbers} numbers, no letters.&quot;)
            break
        else:
            password_letters = password_length - password_numbers
            print(f&quot;&quot;&quot;Your password will be {password_length} characters with {password_numbers} numbers and {password_letters} letters.&quot;&quot;&quot;)
            for letter in range(0,password_letters):
                password.append(random.choice(letters))
            break
    random.shuffle(password)
    password_string = ''.join([str(item) for item in password])
    print(f&quot;Your password is:\n{password_string}&quot;)

password_generator()

Usage example:
Choose the length of your password with numbers between 6 and 15:
Password length: 8
Choose the amount of numbers you want in your password, max 8
Password numbers: 2
Your password will be 8 characters with 2 numbers and 6 letters.
Your password is:
pzc11bmf
letters = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;, &quot;g&quot;, &quot;h&quot;, &quot;i&quot;, &quot;j&quot;, &quot;k&quot;, &quot;l&quot;, &quot;m&quot;, &quot;n&quot;, &quot;o&quot;, &quot;p&quot;, &quot;q&quot;, &quot;r&quot;, &quot;s&quot;, &quot;t&quot;, &quot;u&quot;,`
           &quot;v&quot;, &quot;w&quot;, &quot;x&quot;, &quot;y&quot;, &quot;z&quot;]


This method of writing the alphabet is very error prone. I would import string and use string.ascii_lowercase in place of letters. If you want to generate your own range of letters for whatever reason, I would write
letters = [chr(n) for n in range(ord('a'), ord('z') + 1)]

since there's then no danger of omitting or duplicating a letter.


password_length = 0
password_numbers = []
password_letters = []


These default values are never used. The defaults for password_numbers and password_letters don't make sense since those variables hold numbers. I would delete all three lines.


if not password_length_input.isnumeric():
    print(f&quot;{password_length_input} is not a number, try again:&quot;)
    continue
else:
    password_length = int(password_length_input)
    print(f&quot;Password length: {password_length}&quot;)


I would instead write
try:
    password_length = int(password_length_input)
except ValueError:
    print(f&quot;{password_length_input} is not a number, try again:&quot;)
    continue
print(f&quot;Password length: {password_length}&quot;)



while True:
    if password_numbers == password_length:
        ...
        break
    else:
        ...
        break


There is no sense in having a while loop here since you always break out of it on the first iteration.


range(0,password_numbers)


You can just write range(password_numbers).


password.append(random.randrange(0,9))


This will append a digit from 0 to 8 inclusive, never 9. If you want all ten digits you should write random.randrange(10). Or, perhaps better, use random.choice(string.digits).


password_string = ''.join([str(item) for item in password])


If you use string.digits then every element of password will be a character so you can simplify this to password_string = ''.join(password).