Skip to content

Instantly share code, notes, and snippets.

@saltavenger
Created October 30, 2012 17:22
Show Gist options
  • Save saltavenger/3981673 to your computer and use it in GitHub Desktop.
Save saltavenger/3981673 to your computer and use it in GitHub Desktop.
scrabble
# Keep track of two numbers: the number of letters left in your hand and the total score
score = 0
numbersLeft = int(calculateHandlen(hand))
# As long as there are still letters left in the hand:
while numbersLeft > 0:
# Display the hand
print 'Current Hand: ',
displayHand(hand)
# Ask user for input
word = raw_input('Enter word, or a "." to indicate that you are finished: ').lower()
# If the input is a single period:
if word == '.':
# End the game (break out of the loop)
break
# Otherwise (the input is not a single period):
else:
# If the word is not valid:
if isValidWord(word, hand, wordList) == False:
# Reject invalid word (print a message followed by a blank line)
print 'Invalid word, please try again.'
print
# Otherwise (the word is valid):
else:
# Tell the user how many points the word earned, and the updated total score, in one line followed by a blank line
score += getWordScore(word, n)
print '"' + word + '" earned ' + str(getWordScore(word, n)) + ' points. ' + 'Total: ' + str(score) + ' points'
print
# Update the hand
updateHand(hand, word)
print hand
# Game is over (user entered a '.' or ran out of letters), so tell user the total score
print 'Goodbye! Total score: ' + str(score) + ' points'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment