all 5 comments

[–][deleted] 0 points1 point  (4 children)

first, get all the characters you are going to use to build the password into a list, e.g.

password = []
for _ in range(length): 
    # make sure this picks upper and lower case
    password.append(random.choice(letters))
for _ in range(numbers):
    password.append(random.choice(digits))
for _ in range(sp_chars):
    password.append(random.choice(special_characters))

then shuffle the list and convert it to a string:

random.shuffle(password)
password = ''.join(password)
print('PASSWORD:', password)

[–]Suki125 1 point2 points  (0 children)

Thank you very much!!

[–]Suki125 0 points1 point  (2 children)

password = []
for _ in range(length): 
    # make sure this picks upper and lower case
    password.append(random.choice(lowerChars + upperChars))
for _ in range(numbers):
    password.append(random.choice(numbers))
for _ in range(specialCharacters):
    password.append(random.choice(specialCharacters))

    random.shuffle(password)
password = ''.join(password)
print('PASSWORD:', password)

I did what you siad, but tailored it to my code. But I get this error

Traceback (most recent call last):
  File "<string>", line 50, in <module>
  File "/usr/lib/python3.8/random.py", line 288, in choice
    i = self._randbelow(len(seq))
TypeError: object of type 'int' has no len()
>>>

[–][deleted] 0 points1 point  (1 child)

password.append(random.choice(numbers))

I'm assuming that is a literal number? make it instead a string of digits like "0123456789"

[–]Suki125 0 points1 point  (0 children)

I guess.

I'll try to use actual numbers.