A While loop for Scrabble score


#1



Hi! I'm stuck on Exercise 9: Scrabble_score


The code I wrote give the error "Did you create a function called scrabble_score? Your code threw a "global name 's' is not defined" error. "


I was expecting the code to run smooth, so that it gets the score from the last letter all the way to the first. Please let me know what might have went wrong!!

def scrabble_score(word):
    length = len(word)
    da_score = 0
    
    while length > 0:
        length -= 1
        da_score += score[s.lower(word[length])]
    return da_score

edit: Changed my code to this

def scrabble_score(word):
    lower_word = str.lower(word)
    length = len(lower_word)
    da_score = 0
    
    while length > 0:
        length -= 1
        da_score += score[lower_word[length]]
    return da_score

and it worked for some reason


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.