Scrabble_score 'None' Result


#1



This is the link to Python / Practice_Makes_Perfect / Scrabble_Score
https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/3?curriculum_id=4f89dab3d788890003000096#

I'm not sure if it's behaving incorrectly or not. The view on the right says 'None', but it is accepted (I'm allowed to move on). When I run it through Terminal, it prints out the appropriate scores.

Am I missing something or is it okay that it just prints 'None'?


def scrabble_score(word):
    word_score = 0
    for letter in word:
        word_score += score[letter.lower()]
    return word_score
    print word_score


#2

Your code is correct, it's completely ok that you see None in the output :slight_smile:

Just a small note, this print statement:

print word_score

is unreachable. return statement terminates execution of the function so print statement will never be executed. So it's better to delete it or move it above the return statement:

def scrabble_score(word):
    word_score = 0
    for letter in word:
        word_score += score[letter.lower()]
    print word_score
    return word_score

#3

Awesome, thank you!

And yeah, that totally makes sense for "print". Some of my submissions were being accepted but not showing anything. But that's because I never put in examples to actually print :laughing: I just deleted:

print word_score

and did this after the defined function:

print scrabble_score("Octopus")

Thanks for the help!


#4

You're very welcome! It's always a good idea to include few function calls :slight_smile:


#5

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