Create main.py
This commit is contained in:
commit
14a1ea9fdd
1 changed files with 29 additions and 0 deletions
29
main.py
Normal file
29
main.py
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
|
def generate_password(length=16):
|
||||||
|
characters = string.ascii_letters + string.digits + string.punctuation
|
||||||
|
password = ''.join(random.choice(characters) for _ in range(length))
|
||||||
|
return password
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("Welcome to the Random Password Generator!")
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
length = int(input("Enter the desired password length (default is 16): ") or 16)
|
||||||
|
if length <= 0:
|
||||||
|
print("Please enter a positive number.")
|
||||||
|
continue
|
||||||
|
password = generate_password(length)
|
||||||
|
print(f"Your generated password is: {password}")
|
||||||
|
except ValueError:
|
||||||
|
print("Invalid input. Please enter a number.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
again = input("Do you want to generate another password? (yes/no): ").strip().lower()
|
||||||
|
if again not in ['yes', 'y']:
|
||||||
|
print("Thank you for using the Random Password Generator.")
|
||||||
|
break
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue