On 10/12/2013 15:45, Matthew Thomas wrote:
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


An alternative to the hints kindly provided already by Alan Gauld is to write out a sizeable cheque made payable to the Python Software Foundation, where the size of the cheque refers to the amount in words and figures and not the physical dimensions. Then and only then will you see some actual code.

--
My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to