Question on PS3 #4. I have run into an issue with the first part of my play_hand function. I was successful running the harness test functions for the first 3 functions. When I run the code (pasted in the link below) and enter an invalid word, I cannot escape the "if not... " part of the function. I know that my solution is not correct but I want to know why I can't escape the "if not..." part of the function when I enter an invalid word. I am not as concerned with the solution to the actual problem #4. http://pastebin.com/RjU6Y4QF
Just to clarify. My problem is that when I enter an invalid word, I get prompted to enter a new word. Ok so far so good. But even if that new word is valid, the error message about entering an invalid word is returned. In other words I can't enter a valid word if I first enter an invalid one.
i'm getting a sytax error for the break - i is not 'in' a loop i commented out the break and it worked for me http://dpaste.com/802363/
I tried taking out the break and here is the result that I got: http://pastebin.com/Ff1Z00UJ So when I enter an invalid word, those letters are removed from the hand and I can't use them to make a new valid word. I don't know why this is happening. My get_word_score, update_hand, and valid_word functions all passed their harness tests. Can anyone provide any insight as to why this is happening?
A few things to consider: 1. include all the code, so we don't have to hunt 2. play_hand isn't returning anything, maybe it should? 3. an if should generally have a else statement 4. its probable that is_valid_word never returns True
i put your play_hand() function into my ps3 solution and i did not experience the symptom you described. i gave it several invalid words and it did not remove any letters from hand. I don't see how that could possbly happen with the code from your original post - that function does not do anything other than ask for a word over and over till it gets a valid word then just stops - http://dpaste.com/803364/
I had this same problem originally. The test harness will pass but when you implement play_hand the "hand" gets mutated when you send it to "is_valid_word" so you need to use something like "temp_hand=hand.copy()" at the start of your "play_hand" and send "temp_hand" instead of "hand".
Msmithhnova I think you are probably correct. However I am still having trouble. I just looked at the solution code for PS3 and I am having trouble running #4.
What is it doing or not doing? Also, it would likely be easiest to assist you if you were to post your ps3a.py on one of the code sites.
Join our real-time social learning platform and learn together with your friends!