Download hw2-5.py
and save it as Name_StudentID_HW2-5.py
. Open it in IDLE and press F5.
passwordDictionary
. This is a list of the 25 easiest passwords to break in 2014. First, make sure your password doesn't appear on this list: if it does, you should probably go and change it!printDictionary
with passwordDictionary
as input. Make sure you understand how this function works.printDictionary
so it prints the keys in alphabetical order. We need to sort the list of keys alphabetically. There are two choices:
sorted()
, which takes in a list and returns a sorted version of it. We used this in HW 2-4 when we did sortedList = sorted(myList)
to get the fast version of removeDuplicates
.sort()
, which is called on a list. For example, myList.sort()
. It doesn't return anything, but after calling it on a list, that list will be sorted.myList = ['my', 'name', 'is', 'ChanTaiMan']
. The try using sortedList = sorted(myList)
and print out the contents of sortedList
and myList
. Then try myList.sort()
and print out the contents of myList
. What is the difference between these two methods? Write your explanation in the comments for printDictionary
. Then pick one method and use it in your modification of printDictionary
.addPassword
FunctionFor this next task, we will write a function that will allow the user to add a new name and password to the dictionary. In IDLE, run the echo
function (you can do that by just typing echo()
at the >>>
IDLE prompt.)
input
function do? Write your answer in the comments to echo
addUser
function is supposed to add a user to the dictionary. It should use input()
to get the input from the user, and then call addPassword
to add the password. An example run should look like:
Enter the name of the user: grace
Enter password: 123456
Password and name successfully entered!
addPassword
function, as it's currently written, is a bit dangerous. It's fine if I add a new name and password, but I want to be sure that I don't accidentally overwrite an existing name and password.
addPassword
function to print a statement that says 'Warning, overwriting an existing password!'
if you overwrite a password.'Do you really want to overwrite?'
. If the user enters 'y'
or 'yes'
, then overwrite the password. If the user enters 'no'
(or anything else), print 'Returning original dictionary'
and do not modify the dictionary.updateUserName
allows us to change the name of a user (for example, if he/she typed it in wrong before, or if somebody gives him/herself a new English name.) A sample run of the program should look like the following:
Which user's name do you want to update? Uma What is the the new name? Una Type in the password for Uma: qazwsx "Uma" has successfully been corrected to "Una"
updateUserName
should have some built-in security feature that will require the user to type in his/her correct password before the name can be updated. To practice code reuse, the function should call addPassword
to insert the new user name and password (i.e. if two bits of code do very similar things, they should be extracted into a function, and we can just call that function instead of retyping that code).updateUserName
should also have a security feature that stops the user from picking a name that somebody else is already using! For example:
Which user's name do you want to update? Uma What is the the new name? Valerie Sorry! Valerie is already taken!
Rename your program Name_StudentID_HW2-5.py
and share it with PolyUCOMP1D04@gmail.com
.
Note: Before you turn in your Python files, make sure they run without any errors(Save your Python file. Then select Run > Run Module
or hit F5
on your keyboard)! If nothing appears in the Shell, don't worry as long as no red error messages appear. If they don't run, i.e. if red stuff starts appearing in the shell, points will be taken off!