-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode
More file actions
41 lines (38 loc) · 1.37 KB
/
Copy pathcode
File metadata and controls
41 lines (38 loc) · 1.37 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
34
35
36
37
38
39
40
41
import random
def ranged_input(statement, ranges=(0, 1)):
while True:
try:
x = int(input(f"{statement} from {ranges[0]} to {ranges[1]} : ").strip())
if ranges[0] <= x <= ranges[1]:
return x
else:
print("Please consider range ⚠️")
except:
print("Please enter numbers only ⚠️ !")
def random_char(chartyp):
chars = {
'lowercase': [chr(i) for i in range(97, 123)],
'uppercase': [chr(i) for i in range(65, 91)],
'numbers': [str(i) for i in range(10)],
'special_chars': [
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+',
'[', ']', '{', '}', '\\', '|', ';', ':', "'", '"', ',', '.', '<', '>', '/', '?'
]
}
return random.choice(chars[chartyp])
password = []
num = ranged_input("Please enter how many uppercase letters do you want", (0, 8))
for i in range(num):
password += random_char("uppercase")
num = ranged_input("Please enter how many lowercase letters do you want", (0, 8))
for i in range(num):
password += random_char("lowercase")
num = ranged_input("Please enter how many numbers do you want", (0, 8))
for i in range(num):
password += random_char("numbers")
num = ranged_input("Please enter how many special characters do you want", (0, 8))
for i in range(num):
password += random_char("special_chars")
random.shuffle(password)
password = "".join(password)
print(password)