35 lines
733 B
Python
35 lines
733 B
Python
#imports
|
|
|
|
import string
|
|
import secrets
|
|
|
|
#create password
|
|
|
|
def create_password(length: int) -> str:
|
|
pool = string.ascii_letters + string. digits
|
|
pool += "!?.,-_/;:@"
|
|
|
|
while True:
|
|
|
|
password = ''.join(secrets.choice(pool) for _ in range(length))
|
|
|
|
if any(char.isdigit() for char in password):
|
|
return password
|
|
#length and chek
|
|
while True:
|
|
try:
|
|
length = int(input("Choice the length of the password: "))
|
|
|
|
if length >= 4:
|
|
break
|
|
|
|
else:
|
|
print("the number must be 4 or more")
|
|
|
|
except ValueError:
|
|
print("only numbers are allowed")
|
|
|
|
#output
|
|
|
|
print("password: ", create_password(length))
|