Problem Statement

Write a program that will compute the score of a given word in a game of Scrabble. Assume that there are no special squares present. The program should prompt the user to input a string that only contains letters, and then compute the total score of that string by summing the value assigned to each letter. If the user inputs a string that contains invalid characters, the program should prompt for additional input until a valid word is received.

Handling Input

def main():

main()

Handling Input

def get_input():

def main(): word = get_input()
main()

Handling Input

def get_input():
    word = input("Enter a single word: ")
    while # word is not valid
        print("Error! Invalid Input!")
        word = input("Enter a single word: ")
    return word

def main(): word = get_input()
main()

Handling Input

def get_input():
    word = input("Enter a single word: ")
    while not word.isalpha():
        print("Error! Invalid Input!")
        word = input("Enter a single word: ")
    return word

def main(): word = get_input()
main()

Computing Score

def compute_score(word):

Computing Score

def compute_score(word):
    word = word.lower()

Computing Score

def compute_score(word):
    word = word.lower()
    for letter in word:

Computing Score

def compute_score(word):
    word = word.lower()
    total = 0
    for letter in word:
        # add letter's score to total
    return total

Scrabble Scores

  • (1 point) - A, E, I, O, U, L, N, S, T, R
  • (2 points) - D, G
  • (3 points) - B, C, M, P
  • (4 points) - F, H, V, W, Y
  • (5 points) - K
  • (8 points) - J, X
  • (10 points) - Q, Z

Scrabble Scores

  • (1 point) - A, E, I, O, U, L, N, S, T, R
  • (2 points) - D, G
  • (3 points) - B, C, M, P
  • (4 points) - F, H, V, W, Y
  • (5 points) - K
  • (8 points) - J, X
  • (10 points) - Q, Z

Computing Score

def compute_score(word):
    scores = {"d": 2, "g": 2, "b": 3, "c": 3, "m": 3, "p": 3, 
              "f": 4, "h": 4, "v": 4, "w": 4, "y": 4, "k": 5, 
              "j": 8, "x": 8, "q": 10, "z": 10}
    word = word.lower()
    total = 0
    for letter in word:
        # add letter's score to total
    return total

Computing Score

def compute_score(word):
    scores = {"d": 2, "g": 2, "b": 3, "c": 3, "m": 3, "p": 3, 
              "f": 4, "h": 4, "v": 4, "w": 4, "y": 4, "k": 5, 
              "j": 8, "x": 8, "q": 10, "z": 10}
    word = word.lower()
    total = 0
    for letter in word:
        if letter in scores:
            total = total + scores[letter]
        else:
            total = total + 1
    return total
def get_input():
    word = input("Enter a single word: ")
    while not word.isalpha():
        print("Error! Invalid Input!")
        word = input("Enter a single word: ")
    return word

def compute_score(word): scores = {"d": 2, "g": 2, "b": 3, "c": 3, "m": 3, "p": 3, "f": 4, "h": 4, "v": 4, "w": 4, "y": 4, "k": 5, "j": 8, "x": 8, "q": 10, "z": 10} word = word.lower() total = 0 for letter in word: if letter in scores: total = total + scores[letter] else: total = total + 1 return total
def main(): word = get_input() print(compute_score(word))
main()