태지쌤

로봇 & 코딩교육 No.1 크리에이터

파이썬/exercise

5-4. python 비밀번호 생성기(shuffle)

태지쌤 2023. 1. 4. 11:33
반응형

1. 쉬운 버전

#Password Generator Project
import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']

print("Welcome to the PyPassword Generator!")
nr_letters= int(input("How many letters would you like in your password?\n")) 
nr_symbols = int(input(f"How many symbols would you like?\n"))
nr_numbers = int(input(f"How many numbers would you like?\n"))

#Eazy Level - Order not randomised:
# 1. 문자
password_letter = ""
for l in range(nr_letters):
	password_letter += random.choice(letters)

# 2. 기호
password_symbol = ""
for s in range(nr_symbols):
	password_symbol += random.choice(symbols)

# 3. 숫자
password_number = ""
for n in range(nr_numbers):
	password_number += random.choice(numbers)

# 4. 합치기
password = password_letter + password_symbol + password_number

print(f"your password is {password}")

 

 

2. 어려운 버전

#Password Generator Project
import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']

print("Welcome to the PyPassword Generator!")
nr_letters= int(input("How many letters would you like in your password?\n")) 
nr_symbols = int(input(f"How many symbols would you like?\n"))
nr_numbers = int(input(f"How many numbers would you like?\n"))

password_list = []

password_letter = ""
for l in range(nr_letters):
	password_list += random.choice(letters)


password_symbol = ""
for s in range(nr_symbols):
	password_list += random.choice(symbols)


password_number = ""
for n in range(nr_numbers):
	password_list += random.choice(numbers)

random.shuffle(password_list)

password = ""
for p in password_list:
	password += p
print(f"your password is {password}")
반응형