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

Stumbled upon an interesting issue here while attempting to solve the Ghost game of ps5. Defined a function to do a validity test which returns either True or False. When called individually as a function, it works perfectly, i.e. stops at the first word that matches the given fragment and returns true, or else, runs through the list and returns false. However, when called from the ghost() function, it only returns false, i.e. takes on the predetermined value of the variable 'exists'. More clearly shown here: http://codepad.org/Aw94eiZZ Look out for the function 'wordexist'

OpenStudy (anonymous):

I think that the initialization you did in line #76 is incorrect, also, I think you should add one more condition to the line #83 in order to make the game work as specified in the problem set. Think about it for a while, then if you still have any problems, just ask again.

OpenStudy (anonymous):

One more thing, be careful when you input to your program uppercase letters... think about why.

OpenStudy (anonymous):

you can simplify wordexist to - http://dpaste.com/754577/ if a function returns a boolean or an object has an inherent boolean value, use them in the conditional as-is without an extra variable. for example (lines 82+) http://dpaste.com/754582/ http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#testing-for-truth-values

OpenStudy (anonymous):

You've probably figured out the extra condition by now...On another topic, just to let you know, when I ran your game I had to input the letters with quotes ('s') or else got an error.

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!