A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

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!

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hello, Aslander! Has your question been answered?

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    What's the issue you're having, or error you're getting?

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  9. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  10. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

  11. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

  12. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    return often works well

  13. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Indeed...I think I need a rest...I'm starting to dream in code.

  14. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

  15. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    What've you got so far?

  16. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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...

  17. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    These are the functions I wrote, which have all succeeded. http://dpaste.com/460177/

  18. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  19. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Ok - I'll try doing that and see what happens. Thanks.

  20. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

  21. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I think it works now - I tried playing but I haven't gotten to the point where display_hand = "". http://dpaste.com/463507/

  22. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  23. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  24. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  25. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

  26. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'd need to see your current version of the code.

  27. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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/

  28. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    As well, my quit if/else statement works properly, as it stops the current hand, returns the total score, and starts play_game.

  29. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    your update hand function is still mutating the hand it's givin you need to fix that

  30. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  31. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    This is an example of a non-mutating update_hand function http://dpaste.com/473872/

  32. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  33. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Or rather, my hand is not being mutated, but only my newhand is to return the update?

  34. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  35. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    in your example the names newhand and hand refer to the same object.

  36. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Ooooooohhhhhhh - ic the light now. :-) Thanks for your patience!

  37. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    of course! =)

  38. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Ok - worked on the GHOST assignment and it works so far...no bugs yet!

  39. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Gratz!

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.