Skip to content

Instantly share code, notes, and snippets.

@magi196502
Forked from codecademydev/scrabble.py
Created November 8, 2018 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magi196502/d5d3b55883eb83e3b9a53df006e37753 to your computer and use it in GitHub Desktop.
Save magi196502/d5d3b55883eb83e3b9a53df006e37753 to your computer and use it in GitHub Desktop.
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]
letter_to_points = {key.upper():value for key, value in zip(letters,points)}
letter_to_points[" "] = 0
print(letter_to_points)
def score_word(word):
point_total = 0
word_upper = word.upper()
for letter in word_upper:
point_total += letter_to_points.get(letter)
return point_total
print("The word has a score " + str(score_word("It")))
brownie_points = score_word("BROWNIE")
#print(brownie_points)
player_to_words = {"player1":["BLUE","TENNIS","EXIT"], "wordNerd":["EARTH","EYES","MACHINE"], "Lexi Con": ["ERASER","BELLY","HUSKY"],"Prof Reader":["ZAP","COMA","PERIOD"]}
#print(player_to_words)
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)
def play_word(player,word):
for key in player_to_words:
if player == key:
player_to_words[player].append(word)
def update_point_totals(player):
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
return player_to_points
play_word("player1","ENTER")
print("Words played for player1 ",player_to_words["player1"])
#print(player_to_words["player1"])
print(update_point_totals("player1"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment