import random import string def generate_password(length, digits, special_chars): characters = string.ascii_letters if digits: characters += string.digits if special_chars: characters += '!@#$%^&*' password = '' for _ in range(length): password += random.choice(characters) if digits: password = password[:-1]+"".join(random.choice(string.digits)) if special_chars: password = password[1:]+"".join(random.choice('!@#$%^&*')) passwordl = list(password) random.shuffle(passwordl) password = "".join(passwordl) return password while True: while True: try: length = int(input("How long do you want your password to be?: ")) if type(length) == int and length > 0: break else: print("Please enter a valid number bigger than 0.") except ValueError: print("Please enter a valid number bigger than 0.") digits = input("Do you want to include numbers? (yes/no): ") special_chars = input("Include special characters? (yes/no): ") password = generate_password(length, digits == "yes", special_chars == "yes") print("Your password: " + password) print("Thank you for generating a password!") while True: anotherpass = input("Would you like to generate another password?(yes/no): ") if anotherpass == "no": exit() if anotherpass == "yes": break else: print("Hey you need to write it out tcorrectly or smth (yes/no): ")