Skip to content

Instantly share code, notes, and snippets.

@codecademydev

codecademydev/scrabble.py Secret

Created Mar 15, 2020
Embed
What would you like to do?
Codecademy export
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]
#zipping the two arrays into a dictionary
letter_to_points = {letters:points for letters, points in zip(letters, points)}
letter_to_points[" "] = 0
#function score_word
def score_word(word):
point_total = 0;
for letter in word:
if letter not in letter_to_points:
point_total+=0;
else:
point_total += letter_to_points[letter]
return point_total
#brownie points
brownie_points = score_word("BROWNIE")
print("The word: Brownie scores " + str(brownie_points) + " points in Scrabble")
#players dictionary
player_to_words = {"player1" : ["BLUE", "TENNIS", "EXIT"], "wordNerd" : ["EARTH", "EYES", "MACHINE"], "Lexi Con" : ["ERASER", "BELLY", "HUSKY"], "Prof Reader" : ["ZAP", "COMA", "PERIOD"]}
#function player_to_points
player_to_points = {}
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment