Re: [Tutor] Need to create code
Hi Thomas, In order to use mailing list like Python-tutor effectively, you'll probably want to read: http://www.catb.org/~esr/faqs/smart-questions.html In particular, pay special attention to: http://www.catb.org/~esr/faqs/smart-questions.html#homework You're basically violating the "Don't post homework questions" taboo. This isn't rent-a-coder. We'll be happy to help you learn how to program, but we're not writing your program for you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need to create code
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-' 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
Re: [Tutor] Need to create code
On 10/12/13 15:45, Matthew Thomas wrote: Write a function named *SSN2Name* with an interactive loop. This is obviously some kind of homework exercise. We do not do your homework for you but we will give you pointers or clarify issues if you get stuck. But we expect you to make a start, post your code and any questions. If you have any errors post the entire error message, do not summarize. If you are stuck tell us what happened, what you expected, what version of python, what OS you use. The more specific the question and information you give us the better we can answer. takes the dictionary named*data*as input argument where this dictionary stores the key, value pairs of SSN, name of person. Do you know how to write a function? Do you know how to create/use a dictionary? string format 'xxx-xx-' 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. Do you know how to write a loop? How to get input from a user? How to access a dictionary? How to print output? loop should stop iterating when the user inputs the empty string "" when prompted for SSN. Do you know how to test for an empty string? And how to exit a loop when you find one? 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 What part of that description, if any, do you have a problem with? If you don't have a specific question yet then just go ahead and try to create the code. Come back when you have a specific question and we can try to help. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Need to create code
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-' 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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor