-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHNG.py
196 lines (125 loc) · 5.7 KB
/
HNG.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
from random import sample
from string import ascii_letters, digits
from sys import exit
from pprint import pprint
name, first_name, last_name, gmail, default_password, status, bio_data_container, container = "", "", "", "","", "", {}, {}
user_input = "" # stores input from users
'''name stores the individual names of registered employee
status holds a yes or no response from user
bio_data_container contains the data of each employee
container contains the data of all registered employees
'''
random_strings = "".join(sample(ascii_letters + digits,5)) # a list of random 5-character words
print("Command-line HNG Employees Bio-data Register Application".upper().center(65, "*"))
print()
print("Kindly proceed to filling your bio-data.")
print()
def final_output():
''' this prints the successfully saved bio-data of registered employees
'''
print("You're done saving the bio-data of HNG's employees.", "All saved data are printed below:", sep = "\n")
print()
# Bio-data of all registered employees is printed
pprint(container, width = 20)
# FUNCTION DEFINITION OF MAIN()
def main():
''' this collects the bio-data of employees to be registered and saves it in a super container dictionary for each employee successfully registered
'''
global name, count, bio_data_container, container
first_name = input("Enter your first name: ").title()
while first_name.isalpha() == False or len(first_name) < 2:
print()
print("Invalid input!", "Name should contain only alphabets and it should have more than two characters.", sep = "\n")
print()
first_name = input("Enter your first name: ").title()
print()
last_name = input("Enter your last name: ").title()
while last_name.isalpha() == False or len(last_name) < 2:
print()
print("Invalid input!", "Name should contain only alphabets and it should have more than two characters.", sep = "\n")
print()
last_name = input("Enter your last name: "). title()
print()
gmail = input("Enter your gmail address: ").lower()
# checks for the validity of email addresses
while gmail.endswith("@gmail.com") == False or len(gmail) <= len("@gmail.com"):
print()
print("Invalid input!", "Enter a valid gmail address.", sep = "\n")
print()
gmail = input("Enter your gmail address: "). lower()
default_password = first_name[:2] + last_name[-2:] + random_strings
print()
print(f"Your default password is {default_password}")
print()
print("Are you satisfied with the default password?".title())
user_input = input("Enter y for 'yes' or n for 'no' please: ").lower()
while user_input.isalpha() == False or user_input not in ("yes", "y", "no", "n"):
print()
print("Invalid input!", "Enter y for 'yes' or n for 'no' please.", sep = "\n")
print()
user_input = input("Enter 'y' or 'n' please: ").lower()
if user_input == "no" or user_input == "n":
print()
default_password = input("Enter your preferred password: ")
# checks for password strength
while len(default_password) < 8 or default_password.isalpha() == True or default_password.isnumeric() == True or default_password[0].isupper() == False:
print()
print("Enter a more secure password please.","Hint: Password must start with a capital letter, it must not be less than 8 characters, it must contain numbers.",sep="\n")
print()
default_password = input("Enter your preferred password: ")
else:
pass
print()
name = first_name + " " + last_name
# populating sub-container
bio_data_container["Full_Name"] = name
bio_data_container["Email_address"] = gmail
bio_data_container["Password"] = default_password
# populating super-container
# this prevents two registered employees having the same bio-data
if bio_data_container not in container.values():
container[name +"'s bio-data are:"] = bio_data_container
print(f"{name}'s bio-data saved successfully!")
print()
else:
print("Bio-data NOT saved since it exists!")
print()
next_option()
# FUNCTION INVOCATION OF MAIN()
main()
bio_data_container = {} # this emulates the clearing of the contents of the dictionary storing the previously saved employee bio-data since this dictionary is now in a super dictionary called container & also because the empty bio_data_containerwould be used for subsequent registration of employees
# FUNCTION DEFINITION FOR NEXT_OPTION()
def next_option():
''' this permits the registration of different employees consecutively.
'''
global status, bio_data_container, user_input
print("Do you want to add another employee's bio-data?".upper())
print()
user_input = input("Enter y for 'yes' or n for 'no' please: ").lower()
while user_input.isalpha() == False or user_input not in ("yes", "y", "no", "n"):
print()
print("Invalid input!", "Enter y for 'yes' or n for 'no' please.", sep = "\n")
print()
user_input = input("Enter 'y' or 'n' please: ").lower()
if user_input == "no" or user_input == "n":
status = ("no", "n")
''' this is here because the execution of line 139 doesn't allow line 183 to be executed which needs to be executed for lines 189-190 and 195 to be executed consecutively.
'''
if user_input in ("no", "n"):
print()
final_output()
exit()
elif user_input in ("yes", "y"):
print()
main() # invokes main program body
bio_data_container = {} # emulates clearing of sub-container contents
next_option() # recursive call that keeps asking user if he wishes to register another employee or not
return status
# FUNCTION INVOCATION OF NEXT_OPTION()
status = next_option()
# this is executed when user indicates that no other employee is to registered
if status == ("no", "n"):
pass
print()
# FINAL_OUTPUT INVOCATION
final_output()