-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_generator
More file actions
85 lines (77 loc) · 2.44 KB
/
Copy pathpassword_generator
File metadata and controls
85 lines (77 loc) · 2.44 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# # Students height prgram
# student_heights = input("Input a list of student heights ").split()
# for n in range(0, len(student_heights)):
# student_heights[n] = int(student_heights[n])
#
# s = 0
# count = 0
# for i in student_heights:
# s += i
# count += 1
# avg = round(s/count)
#
# print(avg)
#
# # Finging the highest mark
# student_scores = input("Input a list of student scores ").split()
# for n in range(0, len(student_scores)):
# student_scores[n] = int(student_scores[n])
# print(student_scores)
#
# highest_mark = 0
# for i in student_scores:
# if i > highest_mark:
# highest_mark = i
#
# print(f"The highest score in the class is: {highest_mark}")
#
#
# # Adding the even numbers
# s = 0
# for i in range(1, 101):
# if i % 2 == 0:
# s += i
#
# print(s)
#
# # FizzBuzz game
# for i in range(1, 101):
# if i % 3 == 0 and i % 5 == 0:
# print("FizzBuzz")
# elif i % 3 == 0:
# print("Fizz")
# elif i % 5 == 0:
# print("Buzz")
# else:
# print(i)
# Create a password generator
import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
print("Welcome to the PyPassword Generator!")
nr_letters = int(input("How many letters would you like in your password?\n"))
nr_symbols = int(input("How many symbols would you like?\n"))
nr_numbers = int(input("How many numbers would you like?\n"))
# Eazy Level - Order not randomised:
# e.g. 4 letter, 2 symbol, 2 number = JduE&!91
password = ""
for i in range(0, nr_letters+1):
# You can use password += random.choice(letters) instead of next 2 lines
n1 = random.randint(0, len(letters)-1)
password += letters[n1]
for i in range(0, nr_symbols+1):
n2 = random.randint(0, len(symbols)-1)
password += symbols[n2]
for i in range(0, nr_numbers+1):
n3 = random.randint(0, len(numbers)-1)
password += numbers[n3]
# Hard Level - Order of characters randomised:
# e.g. 4 letter, 2 symbol, 2 number = g^2jk8&P
p = list(password) # convert to list
random.shuffle(p) # Shuffle
password = ''.join(p) # convert back to string
print(password)