Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def play_hand(hand, word_list):
- """
- Allows the user to play the given hand, as follows:
- * The hand is displayed.
- * The user may input a word.
- * An invalid word is rejected, and a message is displayed asking
- the user to choose another word.
- * When a valid word is entered, it uses up letters from the hand.
- * After every valid word: the score for that word and the total
- score so far are displayed, the remaining letters in the hand
- are displayed, and the user is asked to input another word.
- * The sum of the word scores is displayed when the hand finishes.
- * The hand finishes when there are no more unused letters.
- The user can also finish playing the hand by inputing a single
- period (the string '.') instead of a word.
- * The final score is displayed.
- hand: dictionary (string -> int)
- word_list: list of lowercase strings
- """
- word = ''
- total_score = 0
- letters_left = HAND_SIZE
- while word <> '.':
- if letters_left == 0:
- return
- print 'Current Hand:',
- display_hand(hand)
- print 'Enter word, or (.) to indicate that you are finished:',
- word = raw_input().lower()
- if word == '.':
- print 'Total score:', total_score, 'points.',
- return
- elif not is_valid_word(word, hand, word_list):
- print 'Invalid word, please try again.'
- else:
- score = get_word_score(word, HAND_SIZE)
- total_score += score
- print word, 'earned', score, 'points. Total:', total_score, 'points'
- hand = update_hand(hand, word)
- letters_left -= len(word)
Advertisement
Add Comment
Please, Sign In to add comment