From 769e59b0320254661f3a5b643107aac1c0db4f13 Mon Sep 17 00:00:00 2001 From: Khalid Samim <126877550+itkhld1@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:30:32 +0300 Subject: [PATCH] Update main.py --- day05/main.py | 61 +++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/day05/main.py b/day05/main.py index 7532563..6174e8f 100644 --- a/day05/main.py +++ b/day05/main.py @@ -5,37 +5,40 @@ numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+'] -print("Welcome to the PyPassword Generator!") -nr_letters= (input("How many letters would you like in your password?\n")) -nr_symbols = (input(f"How many symbols would you like?\n")) -nr_numbers = (input(f"How many numbers would you like?\n")) - -if not nr_letters.isdigit() or not nr_symbols.isdigit() or not nr_numbers.isdigit(): - print("Invalid value, enter a number instead.") -else: - password = [] - - random_letter = random.randint(0, 51) - for i in range(0, int(nr_letters)): +print("\nWelcome to the PyPassword Generator\n!") + +while True: + nr_letters= (input("How many letters would you like in your password?\n")) + nr_symbols = (input(f"How many symbols would you like?\n")) + nr_numbers = (input(f"How many numbers would you like?\n")) + + if not nr_letters.isdigit() or not nr_symbols.isdigit() or not nr_numbers.isdigit(): + print("Invalid value, enter a number instead.") + else: + password = [] + random_letter = random.randint(0, 51) - password.append(letters[random_letter]) + for i in range(0, int(nr_letters)): + random_letter = random.randint(0, 51) + password.append(letters[random_letter]) - random_number = random.randint(0,9) - for i in range(0, int(nr_numbers)): random_number = random.randint(0,9) - password.append(numbers[random_number]) + for i in range(0, int(nr_numbers)): + random_number = random.randint(0,9) + password.append(numbers[random_number]) - random_symbol = random.randint(0,8) - for i in range(0, int(nr_symbols)): random_symbol = random.randint(0,8) - password.append(symbols[random_symbol]) - - random.shuffle(password) - print(f"Here is your password: {''.join(password)}") - - if len(password) <= 6: - print("Your password is weak, try to include at least 8 characters for a stronger password.") - elif len(password) == 7: - print("Your password is medium, try to include at least 8 characters for a stronger password.") - else: - print("Your password is strong.") + for i in range(0, int(nr_symbols)): + random_symbol = random.randint(0,8) + password.append(symbols[random_symbol]) + + random.shuffle(password) + print(f"Here is your password: {''.join(password)}") + + if len(password) <= 6: + print("Your password is weak, try to include at least 8 characters for a stronger password.") + elif len(password) == 7: + print("Your password is medium, try to include at least 8 characters for a stronger password.") + else: + print("Your password is strong.") + exit()