1import string
2from random import *
3characters = string.ascii_letters + string.punctuation + string.digits
4password = "".join(choice(characters) for x in range(randint(8, 16)))
5print password
6
1import random
2chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@£$%^&*().,?0123456789'
3
4number = input('Please enter a number of passwords.')
5try:
6 number = int(number)
7except:
8 print("Error, please enter a number!")
9
10length = input('Length of password?')
11try:
12 length = int(length)
13except:
14 print("Error, please enter a number!")
15
16print('\nHere are your password(s):')
17
18for pwd in range(number):
19 password = ''
20 for c in range(length):
21 password += random.choice(chars)
22 print(password)
1import string
2import random
3
4length=5
5#python2
6randomstr = ''.join(random.sample(string.ascii_letters+string.digits,length))
7
8
9#python3
10randomstr = ''.join(random.choices(string.ascii_letters+string.digits,k=length))
11
12
1import random
2
3alph = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ\
4 abcdefghijklmnopqrstuvwxyz\
5 1234567890 !@#$%^&*(){}[]<>,.')
6out = ''
7for char in string:
8 out += random.choice(alph)
9
10print(out)
1from random import choice
2from string import printable # variable in the module that contains all the possible chars
3
4# This is optional__________________
5class LengthError(Exception):
6 pass
7
8
9def length_checker(length):
10 if length < 6 or length > 40:
11 raise LengthError("Password length must be between 6 and 40 characterse.")
12#_______________________________________
13
14# removing unwanted characters
15chars = list(printable)
16chars.pop(85)
17for i in range(5):
18 ascii_characters.pop()
19
20
21while True: #loop (optioanl)
22 try:
23 print("Enter your password length:")
24 max_length = int(input())
25 if max_length == 0:
26 exit()
27 length_checker(max_length) # optional
28 password = ""
29 for i in range(max_length):
30 password += choice(ascii_characters)
31 print(f"Your generated password:{password}")
32 except LengthError as e: # optional
33 print(e)
34 except ValueError:
35 print("We can't process this with letters, symplos, emptyspaces or any other non-integer type. Please enter a valid range.")
36
1from random import choice
2from string import printable # variable in the module that contains all the possible chars
3
4# This is optional__________________
5class LengthError(Exception):
6 pass
7
8
9def length_checker(length):
10 if length < 6 or length > 40:
11 raise LengthError("Password length must be between 6 and 40 characterse.")
12#_______________________________________
13
14# removing unwanted characters
15chars = list(printable)
16chars.pop(85)
17for i in range(5):
18 chars.pop()
19
20
21while True: #loop (optioanl)
22 try:
23 print("Enter your password length:")
24 max_length = int(input())
25 if max_length == 0:
26 exit()
27 length_checker(max_length) # optional
28 password = ""
29 for i in range(max_length):
30 password += choice(ascii_characters)
31 print(f"Your generated password:{password}")
32 except LengthError as e: # optional
33 print(e)
34 except ValueError:
35 print("We can't process this with letters, symplos, emptyspaces or any other non-integer type. Please enter a valid range.")
36