반응형
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}")
반응형
'파이썬 > exercise' 카테고리의 다른 글
8-1. python function - math ceil (0) | 2023.01.04 |
---|---|
7. python hangmangame (0) | 2023.01.04 |
5-3. python 짝수의 합 구하기(for반복문 연습) (0) | 2023.01.04 |
5-2. python 최고/최소 점수얻기(for반복문 연습) (0) | 2023.01.04 |
5-1. python 학생 평균키 구하기(for반복문 연습) (0) | 2023.01.04 |