PS5....play_hand: So here is what I've got. http://codepad.org/yACOBEdP I found that if I'm going to run it though a loop, the 'score' variable needs to be independent or else it would just be reset to 0 everytime. I've circumvented this problem by introducing a 3rd argument to the function ie: play_hand(hand, word_list, score). Apparently this wasn't intended, can anyone give me some pointers. AND why when I enter '.' doesn it return my print statement and the 'None' but will also prompt ************Invalid word*************** etc.???????? please help
i interpreted the instructions to mean that the score for each word would be displayed and the total for all words made in the hand would be displayed. if you want to to keep track of the game total, you could return the hand's score to play_game, instead of returning None, and keep track of the game total there. - you wouldn't need the the xtra argument 'AND why' .... you are using recursion at line 16. the topmost function gets to line 16 and creates a new function (the bottom most) - the topmost function suspends execution at line 16 and waits for the new function to return. if '.' is entered in this new/bottom most function it returns None to the next function UP (the top most one) - then the top most fuctions continues execution at line 17 and now that i see that, if you keep the recursive structure the way to dispense with the extra argument would be to pass the word scores up the recursion stack and accumulate it line 16 would be score = score + play_hand(chopH, word_list, score) http://codepad.org/v31g57lC
I suppose my question wasn't as clear as it should have been. To build off what you've given....can I write this function to keep score without the recursive statement in line16? I found that because of the recursion, without the third argument the score never added (for example: score = 0)and would always reset the score when I called the function again. I then tried to omit line 16 to add another 'raw_input' , to try and store this as a new word, to no avail. How do you keep score without the third argument? Thanks for you help
i didn't try to figure it out for yours but the example in my previous post shows how you can accumulate a value using recursion without an extra argument - basically each function adds the value that is returned from the function 'beneath' it I think you should be able to make it work with recursion. I don't think there is a problem with keeping the xtra argument either. it is like - someone has asked you to create a function that returns something specific given specific arguments - as long as you comply with those constraints and your xtra argument doesn't interfere with how the function is called I think it is OK. It can be done without recursion. This might be the first time I have seen this done with recursion - I am curious to see it work. without recursion you just need a loop that continues to ask for words till the user quits or there aren't any letters left. inside the loop you keep track of the total points for all the words that have been made. when the hand is done, you could return the total hand's score to play_game and keep track of the game total in that function
excellent answer. How proficient in programming are you? You sound adept, are you still taking the course, or just helping out? Did you solely use this course? What other resources would you recommend studying?
i am a novice but first learned programming a long time ago - never written anything significant, just snippits when there was a specific need. i haven't finished the course yet. I really like Python - hanging out here helps me learn, every once in a while i pop in on the python irc channel to ask them questions.
right on. I agree, Python seems the most intuitive. I'm trying to learn as much as I can, I really enjoy the endless amount of possibilities inferred in coding. I'm looking to team up with some individuals who enjoy a challenge. I find I've got lots of ideas but no capital to back them. Thus ...here I am teaching myself. If you're interested, let me know. Otherwise...Peace and good luck with it
Join our real-time social learning platform and learn together with your friends!