def play_hand(hand):
"""
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 is 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.
hand: dictionary (string -> int)
words: list of lowercase strings
"""
score = 0
word_list = load_words()
HAND_SIZE = len(hand)
while True:
print "Current hand: ", display_hand(hand)
words = raw_input("Please, enter a word, or '.' to indicate you are finished: ")
'''
hitting dot should break the code, but it doesn't do it
'''
if words == "." or HAND_SIZE == 0:
print "Total score:", score
break
else:
if is_valid_word(words, hand, word_list) == False:
words = raw_input("invalid word, please try again: ")
else:
score = score + get_word_score(words, HAND_SIZE)
print "%s eaed %i pints. Total: %i" %(words, get_word_score(words, HAND_SIZE), score)
hand = update_hand(hand, words)
HAND_SIZE = len(hand)
برچسب:
نویسنده: استخدام کار
تاريخ: جمعه
10 ارديبهشت
1395 ساعت: 21:56