Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 7 Online
OpenStudy (anonymous):

A little stuck on the second part of PS5. So one of the functions has to return a piece of the words in word_list so you can determine if the fragment is able to become a real word. Is there a way to take a list of words and take only, say, the first two letters of every word and compare those to another word to see if that will work? -Ian

OpenStudy (anonymous):

a word is a string and a fragment is a string ... take a look at the methods available for str types - take a good look, never know when you might need one http://docs.python.org/library/stdtypes.html#string-methods

OpenStudy (anonymous):

How's it look? http://codepad.org/g7xvns2D I thought there might be an easier way to handle to switch players bit. I was going to write a function to do it, but got caught up when I remembered that Python handles all variables by reference, but that those would be immutable, so I did what I knew would work and seems to be pretty easy to read. Ignore the play_again boolean, I was fiddling around with having it replay once it's done. The only other sticking point I had was the more than one letter inputed error handling, starts with while new_fragment == old_fragment. It seems like I could have implemented that a little better too. Is that bit of code enough to create another function in your guys' opinions? -Ian

OpenStudy (anonymous):

line 58 seems to contradict what is happening in lines 66-68 Your check for more than one character entered looks/reads fine. I tend to put little things like that in separate functions but after reading yours, it probably didn't need to be. If they tried to enter more than one, i didn't give them a second chance - i used the first letter: http://dpaste.com/665449/ I handled the current player bit the same as you - seems like the simplest way to do it huh? one thing i did different: i used a binary search through the wordlist when looking for a word that starts with the fragment. http://pastebin.com/gzYnfAns "... strings are compared lexicographically.." http://docs.python.org/reference/expressions.html#notin

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!