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

In PS5 the word game, is it the 'helper code' that makes the functions run automatically?

OpenStudy (anonymous):

it also seems to run deal hand and display hand by itself (as well as load word_list and freq dict). I can't understand why. They are functions. I'm probably missing something obvious.

OpenStudy (anonymous):

actually it just runs all of them. Still don't get why.

OpenStudy (anonymous):

load_words( ), get_frequency_dict(sequence), display_hand(hand) and deal_hand(n) are all functions that they've coded for us. If you run the module without typing anything, the little piece of code at the very bottom is executed. It assigns load_words( ) to the variable word_list. Then, play_game( ) is then called with the new variable word_list as its parameter.

OpenStudy (anonymous):

Nah, it's the play game one. That's the function responsible to start the entire game. After all the functions are implemented of course.

OpenStudy (anonymous):

But if you mean the one responsible for loading up the dictionary, yes it's in the 'helper code'.

OpenStudy (anonymous):

Are you talking about this bit at the bottom? http://dpaste.com/568213/ when a module is run like a script (i.e. F5 from the IDLE edit window) its __name__ is '__main__' so the conditional is true an those lines will run. if you import a module ('file') into another module its __name__ isn't '__main__' and those lines won't execute. http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm http://diveintopython.org/getting_to_know_python/testing_modules.html

OpenStudy (anonymous):

Ah, yes I see the bit at the end. it runs load and play, and my play connects to the rest... It doesn't mention the get_dict, so I guess that is the helper code, which specifically says don't worry what it's for but I can't help myself... Great links bwCA

OpenStudy (anonymous):

I did the word game problems today..and i was also wondering about the same thing...that why does the ps4 code doesn't run before the ps5 code... so now i understnd it's the last few lines...they directly execute the ps5 code :) thank u guys... :)

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!