Welcome to Stack Overflow! Contrary to how it may seem, we don't necessarily write code to fix your bugs, and all the contributors on this amazing website are here to help assist you in answering a question.
Anyways, with your problem- there are a couple improvements you could do to the code before generating the actual password, such as turning the strings into one big array of characters which are valid to use in the password. You can accomplish that like so:
import string
# You don't need to use the .upper(), as ascii_letters already contains the uppercase letters
# You can use the list() function to turn a string into an array, splitting it per character
# You can use the + operator to merge strings together
validChars = list(string.ascii_letters + string.digits + string.punctuation)
Also, you don't need to use a new line in order to use the int() function, and you can wrap it around the input() command like so:
passLength = int(input("Pass length? "))
Finally, for actually generating the password. For that, you can use a for
loop to iterate over each letter, and select a character from the array.
passW = ""
for letter in range(passLength):
# random.choice() picks a random item from an array
# In this case, it's a random character from our list of valid characters
passW += random.choice(validChars)
The last thing you need to do is print the password to the screen, so the user can use it:
print(passW)
I haven't tested any of the above code, but that's the gist of it. Please don't actually use this code to generate a random password, the random
module isn't safe for that. Instead, use a module which generates cryptographically safe passwords, like the secrets module.