Scrabble Score Count

142 Views Asked by At

I have been trying to make a scrabble score counter but I end up falling in an infinite loop, I attach my code in case anyone can give me a hand, it personally makes sense, but for some reason Python does not like my code :((

def letterScore(let):
    """Argument let: one character string
    Return Value: the scrabble value of the letter"""
    if let in 'qz':
        return 10
    elif let in 'aelnorstu':
        return 1
    elif let in 'd':
        return 2
    elif let in 'bcmp':
        return 3
    elif let in 'vwy':
        return 4
    elif let in 'k':
        return 5
    elif let in 'x':
        return 8
    else:
        return 0
   
def scrabbleScore (S):
    """"Argument S: String argument S
    Return Value: the total Scrabble score :))"""
    
    
    if "s[0]" == '':
        return 0
    else:
        return letterScore(S[0]) + scrabbleScore (S[1:])

#
# Tests
#
print( "scrabbleScore('quetzal')           should be  25 :",  scrabbleScore('quetzal') )
1

There are 1 best solutions below

0
rikyeah On

As the comments suggested, you should check for the string to be empty with S == ''. The string comparison you had before made no sense, as it was always false.

def scrabbleScore(S):
    """"Argument S: String argument S
    Return Value: the total Scrabble score :))"""
    if S == '':
        return 0
    else:
        return letterScore(S[0]) + scrabbleScore(S[1:])