Guest User

playhand

a guest
Apr 30th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. def element_counter(hand):
  2. """Counts the number of elements in the hand"""
  3. sum = 0
  4. for i in hand.values():
  5. sum = sum + i
  6. return sum
  7.  
  8. def play_hand(hand, word_list):
  9.  
  10. word = ''
  11. total_score = 0
  12. letters_left = element_counter(hand)
  13.  
  14. while word <> '.':
  15. if letters_left == 0:
  16. return
  17. print 'Current Hand:',
  18. display_hand(hand)
  19. print 'Enter word, or (.) to indicate that you are finished:',
  20. word = raw_input().lower()
  21. if word == '.':
  22. print 'Total score:', total_score, 'points.',
  23. return
  24. elif not is_valid_word(word, hand, word_list):
  25. print 'Invalid word, please try again.'
  26. else:
  27. score = get_word_score(word, HAND_SIZE)
  28. total_score += score
  29. print word, 'earned', score, 'points. Total:', total_score, 'points'
  30. hand = update_hand(hand, word)
  31. letters_left -= len(word)
  32. print "letters left", letters_left
Advertisement
Add Comment
Please, Sign In to add comment