goinaction / code

Source Code for Go In Action examples
4.12k stars 2.36k forks source link

import random #140

Open kuxsoq-6jukvy-rekFor opened 10 months ago

kuxsoq-6jukvy-rekFor commented 10 months ago

import random import string

def generate_password(length):

Define the pool of characters to choose from

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: "))

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