-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16password_generator.py
More file actions
33 lines (28 loc) · 1.06 KB
/
Copy path16password_generator.py
File metadata and controls
33 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Write a password generator in Python. Be creative with how you generate
passwords - strong passwords have a mix of lowercase letters, uppercase
letters, numbers, and symbols. The passwords should be random, generating a
new password every time the user asks for a new password. Include your
run-time code in a main method.
Extra:
Ask the user how strong they want their password to be. For weak passwords,
pick a word or two from a list.
"""
from string import ascii_letters, digits
from string import printable
from random import choice
def password_gen():
length = int(input("Enter a password length.\n> "))
strength = input("Enter a password strength. 'weak' or 'strong'.\n> ")
password = []
if strength == "strong":
for i in range(length):
password.append(choice(printable))
elif strength == "weak":
for i in range(length):
password.append(choice(ascii_letters+digits))
else:
print("error. Try again.")
password_gen()
print("Here is your password:\n"+"".join(password))
password_gen()