-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution27.py
More file actions
39 lines (30 loc) · 1.09 KB
/
solution27.py
File metadata and controls
39 lines (30 loc) · 1.09 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
"""
# ex.27
Create a program that register a user with a username and a password. Then the user will try to login with the login
credentials. If the user make 3 wrong attempts exit program with proper message.
Create a program that:
* Reads the username and the password
* Then the user try to login
* If the user makes 3 wrong attempts exit with proper message
"""
def login_info(username, password):
dict_login_info = {}
dict_login_info[username] = password
return dict_login_info
ask_username = input("Enter your username: ")
ask_password = input("Enter your password: ")
info_client_dict = login_info(ask_username, ask_password)
attempts = 0
max_attempts = 3
while attempts < max_attempts:
ask_username_again = input("Enter your username: ")
ask_password_again = input("Enter your password: ")
if ask_username_again in info_client_dict and info_client_dict[ask_username_again] == ask_password_again:
print("Welcome back")
break
else:
print("Try again")
attempts += 1
else:
print("Sorry, your login failed")
exit()