anonymous
  • anonymous
PS.5. Hi all, I'm currently working on PSet 5. If any one wants to exchange ideas - and you're working on the same problems as I am - feel free to post!
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
Hello, Aslander! Has your question been answered?
anonymous
  • anonymous
I'm just starting the assignment now, but already I ran into a problem trying to run the ps5.py...not sure why either...I also tried changing the file name as the handout suggested, to indicate the entire path to the word.txt file, but that didn't work.
anonymous
  • anonymous
What's the issue you're having, or error you're getting?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
2 issues right now: 1. When I run ps5.py I get an empty browser screen. 2. As the handout suggested, I changed the file name to reflect the full path to the wordlist. Still won't run. All files are in the same directory.
anonymous
  • anonymous
Ok Issues solved...I changed the path name to reflect the actual path to the file on my data drive, then typed an r", in front of my drive letter...it solved the problem and it now works as the handout indicates. Thanks guys!
anonymous
  • anonymous
More information about string literals can be found here: http://docs.python.org/reference/lexical_analysis.html#string-literals Of particular note is the raw strings and escape sequence information
anonymous
  • anonymous
Problem 1 was a success - now on to problem 2. I am reading it as: Make a dictionary of the HAND, the letters in HAND as the KEYS, and make their values equal to the amount of times they appear in HAND. Take the letters in WORD, then subtract them, or remove their keys from the HAND. Return remaining letters if any. Did anyone read that any differently?
anonymous
  • anonymous
The function gets the dictionary of the HAND as an argument . You just have to make a copy of it, modify it by removing/decrementing any letters that appear in WORD and return the newly updated/created hand.
anonymous
  • anonymous
Thanks - I rewrote some code and Problem 2 was successful! I totally read it incorrectly. I'll have to be more thorough for Problem 3 now.
anonymous
  • anonymous
So Prob 3 was a success...Prob 4 is giving me trouble. I can get the prog to quit after typing the "." and I can get the hand dealt, and iterate if the word is not valid. However, if I type a valid word, it returns an empty prompt, and I am out of the loop. My call to "update_hand" seems to be erroneous...and I thought it would be straightforward!
anonymous
  • anonymous
Problem 4 - not so easy. So far I can display the hand, and while the word is in wordlist, update word while printing the score. Now how to quit the loop and return the grand score?
anonymous
  • anonymous
return often works well
anonymous
  • anonymous
Indeed...I think I need a rest...I'm starting to dream in code.
anonymous
  • anonymous
Still working at this - no success yet. If I can't get this thing working soon I'll have to go back and start at step one!
anonymous
  • anonymous
What've you got so far?
anonymous
  • anonymous
My functions have all been successful. However, when I get to the play hand function...which is problem 4, I suck out. It seems that I don't have the functions calling in the correct sequence, with the proper arguments. I'll paste some code in a few...
anonymous
  • anonymous
These are the functions I wrote, which have all succeeded. http://dpaste.com/460177/
anonymous
  • anonymous
I see a few bugs in your approach. Firstly in get_word_score you need to award the bonus 50 points if len(word) >= n, not if n and len(word) are >= 7. Secondly, update hand is supposed to return a new hand with the letters removed, it is not supposed to alter the hand it's given. Third issue. You are altering the hand in your is_valid_word function. Don't do this. You should be comparing the letter counts in word to the counts in hand, but not decrementing the count from the hand. Try fixing these bugs and see if you get the right behavior.
anonymous
  • anonymous
Ok - I'll try doing that and see what happens. Thanks.
anonymous
  • anonymous
So how am I supposed to return the new hand without mutating it? I only decrement the values for each key, and then return the keys with >0 values. Is that the same as mutating the hand?
anonymous
  • anonymous
I think it works now - I tried playing but I haven't gotten to the point where display_hand = "". http://dpaste.com/463507/
anonymous
  • anonymous
In answer to your question about mutating it. Yes, that is changing the hand you are given. The easiest way to prevent mutating the original hand is to make a copy of it. new_hand = dict(hand) then work with new_hand (and return it) while leaving hand alone.
anonymous
  • anonymous
while display_hand != "": this will not do what you intend. display_hand is a function. Functions are not comparable with strings in any sensible way, and it doesn't return anything either, so don't try changing it to display_hand(hand) != ''. hand == "" is also not a comparison you should be doing, (maybe you want to check if the dictionary is empty?). Please elaborate further on what your thought process is for this algorithm.
anonymous
  • anonymous
Checking if Dict is empty...now why didn't I think of that! I was going all over the place - check for values being 0, or not, etc. Good idea polpak! I did get all the functions to work, except the automatic quit when update_hand returns the empty string. My idea was that if the displayed hand was empty, then it would execute the quit or ".". So if I set a condition that checks if display_hand returns nothing, then it would execute the QUIT. I did realize however, earlier today, that it wouldn't work, but couldn't figure out what to do next. Thanks - I'll try something and see what happens.
anonymous
  • anonymous
So I finally got the empty hand issue resolved, and the program seemed to work like a charm, except I get this one bug that I think is due to the hand still being mutated, during the update_hand cycle.For some reason, if I use a letter in the word once, that occurs twice in the hand, when I update, it removes both letters. Ex. If the display hand has two r's, and I use one, when I update, both r's disappear. But that only happens occasionally...or when the letters appear at the beginning of the hand...which is beyond me. Any ideas why that would be?
anonymous
  • anonymous
I'd need to see your current version of the code.
anonymous
  • anonymous
So here is my code for the play_hand and update...which I think may be the problem...but the rest of the script works well. I get the proper return score when there are no double letters, etc. http://dpaste.com/473845/
anonymous
  • anonymous
As well, my quit if/else statement works properly, as it stops the current hand, returns the total score, and starts play_game.
anonymous
  • anonymous
your update hand function is still mutating the hand it's givin you need to fix that
anonymous
  • anonymous
I just changed something and it seemed to have fixed that bug: My 2nd while statement - changed from while to elif: elif is_valid_word(word, hand, word_list) == True: I checked a hand with two l's and used one. It returned it properly...but I haven't seen all other scenario's.
anonymous
  • anonymous
This is an example of a non-mutating update_hand function http://dpaste.com/473872/
anonymous
  • anonymous
Ok so basically you take a count of the letter in word, then use that as a value in the new dict, newhand. Isn't this really the same, as my newhand is not hand? newhand = hand for i in word: newhand[i] = newhand.get(i,0) - 1 return newhand
anonymous
  • anonymous
Or rather, my hand is not being mutated, but only my newhand is to return the update?
anonymous
  • anonymous
hand is being mutated in your example because newhand is the same dictionary as hand. in my example, newhand is a brand new dictionary which we add keys to and return.
anonymous
  • anonymous
in your example the names newhand and hand refer to the same object.
anonymous
  • anonymous
Ooooooohhhhhhh - ic the light now. :-) Thanks for your patience!
anonymous
  • anonymous
of course! =)
anonymous
  • anonymous
Ok - worked on the GHOST assignment and it works so far...no bugs yet!
anonymous
  • anonymous
Gratz!

Looking for something else?

Not the answer you are looking for? Search for more explanations.