Created
May 26, 2025 13:38
-
-
Save marcelosanto/dfefcdc153184e6e6555b7115c8c1b7d to your computer and use it in GitHub Desktop.
minha solução
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
| import random | |
| import string | |
| def gerar_senha(): | |
| while True: | |
| try: | |
| qtd = int(input("Digite o número de caracteres da senha (maior que 0): ")) | |
| if qtd <= 0: | |
| raise ValueError("A quantidade precisa ser maior que zero.") | |
| break | |
| except ValueError as e: | |
| print(f"Erro: {e}") | |
| letras = string.ascii_letters | |
| numeros = string.digits | |
| especiais = string.punctuation | |
| todos_caracteres = letras + numeros + especiais | |
| senha = ''.join(random.choices(todos_caracteres, k=qtd)) | |
| print(f"Senha gerada: {senha}") | |
| gerar_senha() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment