225k views
0 votes
Password generator code on python

User Phyllie
by
8.4k points

1 Answer

4 votes

Final answer:

Computers and Technology. In Python, you can create a password generator using the 'random' module by writing a code that prompts the user for the desired length and prints out the generated password.

Step-by-step explanation:

The correct answer is option Computers and Technology. In Python, you can create a password generator by using the 'random' module. Here's an example code:

import random
import string

def generate_password(length):
characters = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(characters) for _ in range(length))
return password

length = int(input('Enter the length of the password: '))
password = generate_password(length)
print('Generated password:', password)

This code imports the 'random' and 'string' modules, defines a function 'generate_password' that takes a length parameter, generates a password using random characters from the 'characters' string, and returns the password. Finally, it prompts the user for the desired length and prints out the generated password.

User Evan Brumley
by
9.1k points

No related questions found