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

In ps3, the function "display_hand" (http://dpaste.com/804650/) seems to be returning None, which looks stupid when it interrupts every hand of the word game. Why does this happen, and how can I fix it?

OpenStudy (anonymous):

how are you calling it?

OpenStudy (anonymous):

The 'display_hand' routine does not say in the specification that it returns anything and it does not, nor does it need to. You simply call it with 'display_hand(hand)' and it iterates through the letters in hand and prints them out for you.

OpenStudy (anonymous):

python functions always return something. if you do not tell it what to return, it will return None. http://pastie.org/4790675

OpenStudy (anonymous):

in case it wasn't clear from the previous replies, the display_hand function has no return value specified. Instead, the function itself does the printing. If you run "print display_hand(hand)", it will display the hand as well as print the return value, which is "None" in this case. If you simply call the function print "Here is your hand" display_hand(hand) you will not have this problem.

OpenStudy (anonymous):

Aha! I was printing display_hand. Thank you for the replies! I reworked the function to return the hand instead, like so: http://pastebin.com/wCtDj30R

OpenStudy (anonymous):

here is another way to do it - using a list comprehension http://pastie.org/4816135

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!