9/15 scrabble score


#1

Hello. These are my final code that passed:

def scrabble_score(word):
	point = 0
	for letter in word.lower():
		for key in score:
			if letter == key:
				point += score[key]
	return point


What confuses me is that my original work didn't work in the first place:

def scrabble_score(word):
	word.lower()
	point = 0
	for letter in word:
		for key in score:
			if letter == key:
				point += score[key]
	return point

Would anyone please point out the difference for me? I would be really appreciating!


#2

Hey.
word.lower() returns the all lower-case version of the word, but doesn't change the original string. In your original code you call the .lower() function but don't save or use the returned string anywhere.
Hopefully this clears something things.


#3

Thank you so much for your reply! Is there any way that helps beginner to improve on these kind of details? I guess the only way is keep practicing?


#4

No problem :slightly_smiling: Usually these kind of things just start to stick with you with experience, so just keeping on coding will make it easier. Also know that you're not alone! Quick googling will get you all sorts of answers and insights as there are a bunch of threads all over the web about coding problems.
One good way to check how different functions work is check the reference material for them or just googling the function.


#5

According instruction,below code is complete code and I think your the variable of first line is not assigned just like above .

def scrabble_score(word):
original = word.lower()
if original.isalpha() and original != " ":
total = 0
for i in original:
for original in score:
if i == original:
total += score[original]

    return total

else:
    print "Re-enter a word!"

print scrabble_score("pie")