Python

 

Introduction

Scrabble is a popular word game where players form words on a board using letter tiles, each of which has a point value. In this tutorial, we will learn how to calculate the score of a Scrabble word using Python.

Objective

The objective of this tutorial is to write a Python program that calculates the score of a given word in the game of Scrabble. Each letter in Scrabble has a different point value, and we will use these values to compute the score of any word provided as input.

Python Code

# Scrabble Score Calculator Program in Python

# Define the score for each letter in Scrabble
scrabble_scores = {
    'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4,
    'I': 1, 'J': 8, 'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3,
    'Q': 10, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 4, 'W': 4, 'X': 8,
    'Y': 4, 'Z': 10
}

def calculate_scrabble_score(word):
    """
    Calculate the Scrabble score for the given word.
    
    Parameters:
    word (str): The word for which the score is to be calculated.
    
    Returns:
    int: The total score of the word.
    """
    score = 0
    for letter in word.upper():
        if letter in scrabble_scores:
            score += scrabble_scores[letter]
    return score

# Input word from the user
word = input("Enter a word to calculate its Scrabble score: ")
score = calculate_scrabble_score(word)
print(f"The Scrabble score for the word '{word}' is: {score}")

Explanation of the Program

In the program, we first define a dictionary scrabble_scores where each key is a letter of the alphabet and the value is its corresponding point value in Scrabble.

The calculate_scrabble_score function takes a word as input, converts it to uppercase (since Scrabble tiles are case-insensitive), and then iterates through each letter in the word. For each letter, it checks if it exists in the dictionary and adds its score to a running total. Finally, the total score is returned.

The program prompts the user to enter a word and calculates its Scrabble score using the function. The result is then printed to the console.

How to Run the Program

  1. Ensure you have Python installed on your machine. You can download it from the official Python website.
  2. Create a new Python file (e.g., scrabble_score.py) and copy the code above into it.
  3. Open a terminal or command prompt and navigate to the directory where the file is saved.
  4. Run the program by typing python scrabble_score.py (or python3 scrabble_score.py on some systems) and press Enter.
  5. Enter a word when prompted, and the program will calculate and display the Scrabble score for that word.
© 2025 Learn Programming. All rights reserved.

 

By Aditya Bhuyan

I work as a cloud specialist. In addition to being an architect and SRE specialist, I work as a cloud engineer and developer. I have assisted my clients in converting their antiquated programmes into contemporary microservices that operate on various cloud computing platforms such as AWS, GCP, Azure, or VMware Tanzu, as well as orchestration systems such as Docker Swarm or Kubernetes. For over twenty years, I have been employed in the IT sector as a Java developer, J2EE architect, scrum master, and instructor. I write about Cloud Native and Cloud often. Bangalore, India is where my family and I call home. I maintain my physical and mental fitness by doing a lot of yoga and meditation.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)