Jul 30, 2024
eSn9%#()
.random.choice
and random.shuffle
.random.shuffle
to shuffle the characters in the generated list for a strong password.import random
letters = ['a', 'b', 'c', ..., 'A', 'B', 'C', ...]
numbers = ['0', '1', '2', ..., '9']
symbols = ['!', '@', '#', ...]
print("Welcome to the Password Generator!")
input()
and converting to integers.
n_letters = int(input("How many letters? "))
n_symbols = int(input("How many symbols? "))
n_numbers = int(input("How many numbers? "))
password = ""
for _ in range(n_letters):
password += random.choice(letters)
for _ in range(n_symbols):
password += random.choice(symbols)
for _ in range(n_numbers):
password += random.choice(numbers)
password_list = list(password)
random.shuffle(password_list)
password = ''.join(password_list)
print("Your password is: ", password)
random.choice()
: Selects random elements from a list.random.shuffle()
: Shuffles elements in a list.+=
for combining characters.