Working on pset5, problem #4. I am almost done, and my code works, here is the link: http://codepad.org/cEVOikCl. The issue is that I seem to be returning None from one of my functions and I don't know how to get rid of it. A sample output with an example of this is below. Here is a sample output: User hand: a c u w w g g None Please enter a word or a . to indicate you are finished: wag wag earned you 7 points Total score: 7 User hand: c u g w None Please enter a word or a . to indicate you are finished: . Thank you for playing, your total score at the time of exit: 7
I am positive the error comes from the display_hand function, shown here: http://codepad.org/clxbpihk. I guess because I'm not returning a value it is saying so, but how do I stop this? Am I implementing this wrong in my code? Thanks!
somehow when you add your links there is always a period at the end, resulting in a 404 error until you remove the period (if you notice it). - that happened in your previous post too well you are telling Python to print the return value of display_hand which as you guessed is returning None. You can do two things - have the function return the string that you want to print (instead of printing it itself) or have the function return something benign like a space or a colon or a dash or an empty string ..... or put the call to display_hand on the next line (not 'in' the print statement) here is a suggestion for lines 44, 47 - http://codepad.org/XrizYvw0 try to avoid comparing an expression that evaluates to a boolean to True or False - just use the expression itself http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#testing-for-truth-values and to go a bit further ... http://codepad.org/PR5kH6e3 does play_hand work?? i can't tell what you are doing with HAND_SIZE - unless update_hand modifies HAND_SIZE won't it always be greater than zero?
I think I am putting a period at the end out of habit, apologies. Thanks for all the suggestions, your help has been really valuable.
Oh I just realized I didn't answer you. HAND_SIZE is always >0 except when all the letters are used, then the game exits automatically and prints out "well done all the letter were used, your score is ___". However, it is unlikely the user uses all the letters and in that case it is up to them to enter a "." to finish the hand.
I had thought that HAND_SIZE was being used a a constant to specify the size of the hand at the beginning of the hand - not a variable to be manipulated during execution - that's why i was confused.
actually I was using it as a constant! Thanks for pointing that out, I just went and fixed it.
Join our real-time social learning platform and learn together with your friends!