characters = string.ascii_letters + string.digits + string.punctuation
# Generate a password by randomly selecting characters from the pool
password = ''.join(random.choice(characters) for _ in range(length))
return password
Get the desired password length from the user
length = int(input("Enter the desired length of the password: "))
import random import string
def generate_password(length):
Define the pool of characters to choose from
Get the desired password length from the user
length = int(input("Enter the desired length of the password: "))
Generate and print the password
password = generate_password(length) print("Generated password:", password)
Originally posted by @bhanu1030 in https://github.com/goinaction/code/issues/124