Python : Scrabble Game

So I came across this Scrabble Game question where one types in a word they should calculate the score based on the words they typed in.  So after more than a year I haven’t really touch coding, I decided to give this a try so this is what I got.

#Scrabble Game
letters=[]
score=0
count=0

#Defining score feature
def checkScores(x):
    return {
        ‘a’: 1,
        ‘b’: 3,
        ‘c’: 3,
        ‘d’: 1,
        ‘e’: 2,
        ‘f’: 2,
        ‘g’: 4,
        ‘h’: 1,
        ‘i’: 4,
        ‘j’: 5,
        ‘k’: 8,
        ‘l’: 3,
        ‘m’: 1,
        ‘n’: 1,
        ‘o’: 1,
        ‘p’: 10,
        ‘q’: 3,
        ‘r’: 1,
        ‘s’: 1,
        ‘t’: 1,
        ‘u’: 1,
        ‘v’: 4,
        ‘w’: 4,
        ‘x’: 4,
        ‘y’: 8,
        ‘z’: 10
    }.get(x.lower(), 0)

print(‘Scrabble Game’)
word = input(‘Enter a word: ‘)
letters = [x.strip() for x in word]

print(‘*****************************’)
print(‘* Letter * Score *’)
print(‘*****************************’)

#Loop to display letters and calculate score for each letters
for count in range(len(letters)):
    checkPoint = int(checkScores(letters[count]))
    if checkPoint != 0 :
        print(‘* ‘,letters[count],’ * ‘,checkPoint,’ *’)
        print(‘*****************************’)
        if score ==0 :
            score = checkPoint
        else:
            score = score +checkPoint

print (‘Total Score :’,score)

What I noticed about Python is that there’s not really a switch case thing but using a dictionary instead which pretty much works the same.  Initially I was using if else statement, but it was quite messy.  Never the less, it’s the best I could think of at the moment.  Might try something else in the future.

By Alex

If my post helped you, I would appreciate if you help share it. Also it would be good if you can buy me a cup of coffee as well to help keep this site up and running. Thank you.

Related Post

2 thoughts on “Python : Scrabble Game”
  1. Hello Alex,
    I want to desactivTe the fitbit bit function from the watch gps. First time I activated the watch , I was able to see the health menu in se teacker and now eveytime I log in , I can’t see it anymore. I want to display the date instead of that person standing i the watch display , not sure how to disactivate it
    Can you help

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.