How do I define a function?


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/1/3?curriculum_id=4f89dab3d788890003000096#


I got this error: Oops, try again. Did you create a function called scrabble_score? Your code threw a "global name 'scrabble_score' is not defined" error.


I know my code is probably wrong on multiply levels but I specifically want to know why it's saying "global name 'scrabble_score' is not defined", I like to think I at least know how to define a function.


def scabble_score(word):
    total=0
    for key in word:
        if word[key]==score[key]:
            
            total+=score[key]
    return total


#2

There is a spelling mistake in your functions name. You wrote "scabble" instead of "scrabble". This will solve the error. :slight_smile:


#3

No comparison necessary. Also, it will never work since key is a letter, and score[key] is a number.

A much simpler approach...

for letter in word:
    total += score[letter]

#4

Thanks to the both of you, I'm still such a butthead at this.


#5

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