In this exercise, we create a simple password manager using lists in Python 3. Using lists allows us to add and/or remove passwords from the lists. We can use it for PINs as well.
When the user inputs a password or PIN that is in the list, the message ‘Access
Granted’ is displayed.
Else if the password or PIN is not in the list, the message ‘Access
Denied' is displayed.
You can compare with my codes below:
passwords
= [9001, 9002, 9003]
p = int(input('Enter password>'))
if p in passwords:
print('Access Granted')
else:
print('Assess Denied!')
We can
add to the list by using the .append method and the new password will be
included to the list.
passwords
= [9001, 9002, 9003]
passwords.append(9004)
p = int(input('Enter password>'))
if p in passwords:
print('Access Granted')
else:
print('Assess Denied!')
We can
delete a password from the list using the .remove method. After removing a
password, if we try to input it we would get the message ‘Access Denied’
passwords
= [9001, 9002, 9003]
passwords.append(9004)
passwords.remove(9001)
p = int(input('Enter password>'))
if p in passwords:
print('Access Granted')
else:
print('Assess Denied!')
We can do more creative things with the password manager when writing
specific codes.
No comments:
Post a Comment