Why does my code not return the total?


#1


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


Basically my code does not give me back the score even if I print it. I get None.


What is the problem that needs to be fixed in order for the code to work and return the total?


def scrabble_score(word):
    letters=[]
    word = word.lower()
    total= 0
    
    for w in word:
        letters.append(w)
    return letters
    for letter in letters:
        for s in score:
            if s == letter:
                break
        else:
            total += score[s]
    return total


#2

Don't complicate it, just keep it as simple as possible.

def scrabble_score(word):
(4 spaces) total = 0
(4 spaces) for i in word:
(4 spaces)(4 spaces) total = total+score[i.lower()]
(4 spaces) return total
print scrabble_score("Word")


#3

Two problems there,

Point1.
This line..
return letters (Get rid of it?)
You're not getting None (It's probably due to CC interpreter), You're getting a list with word's letter separated.
It's due to early introduction of return statement.
return statement makes your function halt at mid of the code, as by nature.

Point 2.
Now in second part,You're using two loops, You can shorten it by just looping over your letters list and adding the corresponding value by using list ( letters list) item as key of score.

hint**
for s in letters:


#4

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