Last active
June 10, 2020 10:07
-
-
Save MrN00b0t/32b64a146a41d9591ac564de86caa6a5 to your computer and use it in GitHub Desktop.
Codecademy: Scrabble project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] | |
points = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 4, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10] | |
letter_to_points = {letter:point for letter, point in zip(letters,points)} | |
#add lower case letter point values | |
letter_to_points.update({letter.lower():point for letter, point in zip(letters, points)}) | |
letter_to_points[' '] = 0 | |
#Establish the score of a given word | |
def score_word (word): | |
point_total = 0 | |
for letter in word: | |
point_total += letter_to_points.get(letter, 0) | |
return point_total | |
#brownie_points = score_word('BROWNIE') | |
#print(brownie_points) | |
#test game in progress | |
player_to_words = {'player1': ['BLUE', 'TENNIS', 'EXIT'], 'wordNerd': ['EARTH', 'EYES', 'MACHINE'], 'Lexi Con': ['ERASER', 'BELLY', 'HUSKY'], 'Prof Reader': ['ZAP', 'COMA', 'PERIOD']} | |
player_to_points = {} | |
#function to update and print current scores by player | |
def update_point_totals(): | |
for player, words in player_to_words.items(): | |
player_points = 0 | |
for word in words: | |
player_points += score_word(word) | |
player_to_points[player] = player_points | |
print(player_to_points) | |
#function to add word to list of words played by a player | |
def play_word(player, word): | |
player_to_words[player].append(word) | |
return | |
#test lines to represent playing a word | |
#update_point_totals() | |
#play_word('player1', 'test') | |
#update_point_totals() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment