-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassword_Generator.py
50 lines (40 loc) · 1.16 KB
/
Password_Generator.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import string
import random
# create lists
s1 = list(string.ascii_lowercase)
s2 = list(string.ascii_uppercase)
s3 = list(string.digits)
s4 = list(string.punctuation)
# shuffle lists
random.shuffle(s1)
random.shuffle(s2)
random.shuffle(s3)
random.shuffle(s4)
# get length of password from user
get_num = input("enter the length of passwword : ")
# check user's input:
while True:
try:
get_num = int(get_num)
if get_num < 6:
get_num = input("enter the length of passwword should be > 6 : ")
else:
break
except:
print("you should print numbers inly")
get_num = input("enter number : ")
# determine the percentage of letters & digits & punctuations
part1 = round(get_num * (30 / 100))
part2 = round(get_num * (20 / 100))
# create empty list for password
password = []
# start store characters in password list
for i in range(part1):
password.append(s1[i])
password.append(s2[i])
for i in range(part2):
password.append(s3[i])
password.append(s4[i])
random.shuffle(password) # Shuffle characters
password = "".join(password) # convert list to string
print(password) # print final password