[Tutor] Need to create code
Matthew Thomas
mattscot1010 at hotmail.com
Tue Dec 10 16:45:36 CET 2013
Write a function named SSN2Name with an interactive loop. The function takes the dictionary named data as
input argument where this dictionary stores the key, value pairs of
SSN, name of person. The SSN is in the string format 'xxx-xx-xxxx' and
name is also a string. Each iteration of the functions's loop should
prompt the user to enter an SSN in the required format and next, it
should print the name of the person if he/she is found in the
dictionary, otherwise a message like "person not found" if that SSN does
not exist in the keys of the dictionary. The loop should stop iterating
when the user inputs the empty string "" when prompted for SSN.
Write the full function definition in your answer. The function outline is given below with comments provided as code hints -
def SSN2Name(data):
# create a loop that repeats forever (while True loop)
# within the loop prompt user for SSN
# if user input is empty string break out of loop
# if user input is an SSN found as a key in the dictionary, print the value corresponding to that key
# if user input is not found as a key in the dictionary print message saying person was not found
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131210/85313a24/attachment.html>
More information about the Tutor
mailing list