From 28fb451c00b6bfb1d6689430f2a8a9c7046bb57b Mon Sep 17 00:00:00 2001 From: Ulzahk Date: Mon, 31 Aug 2020 08:24:07 -0500 Subject: [PATCH 1/2] Challenge's answer using random choice, randint and lists --- src/main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main.py b/src/main.py index fc9a525..2a8fa00 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,27 @@ # Resolve the problem!! import string +import random + SYMBOLS = list('!"#$%&\'()*+,-./:;?@[]^_`{|}~') +LETTERS = list('abcdefghijklmnopqrstuvwxyz') +CAPITAL_LETTERS = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') +NUMBERS = list('0123456789') def generate_password(): # Start coding here + characters = SYMBOLS + LETTERS + CAPITAL_LETTERS + NUMBERS + password = [] + random_password_length = random.randint(12, 16) + + for i in range(random_password_length): + random_character = random.choice(characters) + password.append(random_character) + + password = ''.join(password) + + return password def validate(password): From 84ee2e7093cdbe34f5ae0162989ca4d7af2ca375 Mon Sep 17 00:00:00 2001 From: Ulzahk Date: Mon, 31 Aug 2020 08:36:45 -0500 Subject: [PATCH 2/2] Fixed missing one special character problem --- src/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index 2a8fa00..9fd5c55 100644 --- a/src/main.py +++ b/src/main.py @@ -13,14 +13,22 @@ def generate_password(): # Start coding here characters = SYMBOLS + LETTERS + CAPITAL_LETTERS + NUMBERS password = [] - random_password_length = random.randint(12, 16) + + one_SYMBOL = random.choice(SYMBOLS) + one_LETTER = random.choice(LETTERS) + one_CAPITAL_LETTER = random.choice(CAPITAL_LETTERS) + one_NUMBER = random.choice(NUMBERS) + + password.extend([one_SYMBOL, one_LETTER , one_CAPITAL_LETTER, one_NUMBER]) + random_password_length = random.randint(4, 12) for i in range(random_password_length): random_character = random.choice(characters) password.append(random_character) + random.shuffle(password) password = ''.join(password) - + return password