Created
August 30, 2022 05:01
-
-
Save timrprobocom/289400ca440fd365bdf4b2f6dc1584dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This does what you are trying to do, but with all the extraneous code eliminated. | |
Notice that strings are iterables, just like lists. Any time you are making a list | |
of single characters, you should probably use a string. Also notice that we write | |
`'xxx'.upper()`, not `str.upper('xxx')`. Also note that it is silly to write ` | |
if result='N': pass`. Just test for what you want to know. | |
""" | |
import random | |
lower_case_letters = 'abcdefghijklmnopqrstuvwxyz' | |
upper_case_letters = lower_case_letters.upper() | |
numbers = "1234567890" | |
symbols = '!@#$%^&*()-_=+.,/:l"[{]`|' | |
result = '' | |
choice = input("Do you want lower case letters? [Y] for YES and [N] for NO").upper() | |
if choice == "Y": | |
result = result + lower_case_letters | |
choice = input("Do you want upper case letters? [Y] for YES and [N] for NO").upper() | |
if choice == "Y": | |
result = result + upper_case_letters | |
choice = input("Do you want numbers? [Y] for YES and [N] for NO").upper() | |
if choice == "Y": | |
result = result + numbers | |
choice = input("Do you want symbols? [Y] for YES and [N] for NO").upper() | |
if choice == "Y": | |
result = result + symbols | |
choice = input("Do you want to repeat characters? [Y] for YES and [N] for NO").upper() | |
length = int(input("length of password")) | |
password = [] | |
if choice == "N": | |
while len(password) < length: | |
password.append(random.choice(result)) | |
else: | |
result = random.shuffle(result) | |
password = result[:length] | |
print(''.join(password)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment