Code working in Atom but not in Codeacademy?


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/scrabblescore?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
I use ATOM as an IDE to play around with and test different variations of my code. The code that I wrote in ATOM works perfectly when tested but not when I copy this into Codeacademy.
Here is my code:


def scrabble_score(word):
    word_score = 0
    word = word.lower()
    for i in word:
        letter_score = score[i]
        word_score += letter_score

    print word_score

scrabble_score("pie")

and here is the codeacademy code:

def scrabble_score(word):
  word = word.lower()
  total = 0
  for letter in word:
    for leter in score:
      if letter == leter:
        total = total + score[leter]
  print total

  scrabble_score("pie")

<What do you expect to happen instead?>
When I copy my code (that works outside of the Codeacademy IDE) into Codeacademy it does not work. And visa versa, the Codeacademy code also does not work when I copy it into my ATOM IDE and try to run it from there.

def scrabble_score(word):
    word_score = 0
    word = word.lower()
    for i in word:
        letter_score = score[i]
        word_score += letter_score

    print word_score

scrabble_score("pie")

#2

so what could between the python interpreter on your computer vs the one on codecademy, maybe the version? Do you know which python version each uses? Maybe the versions are different, and maybe this has an impact

read this very careful:

Define a function scrabble_score that takes a string word as input and returns the equivalent scrabble score for that word

there is one very important word in this set of instructions. Spot it yet? Here is a hint:

return


#3

Thanks for the quick reply.
I have Python 2.7.14 on my computer, not sure where to check the version on Codeacademy?

Ahh, I usually replace “return” with print when I do the exercises outside of Codeacademy in order to check what the code is doing. probably forgot to change then when copying into Codeacademy.

thanks for the help!


#4
import sys
print sys.version

but why not simply include a print statement in front of the function call to get the returned result:

def scrabble_score(word):
    word_score = 0
    word = word.lower()
    for i in word:
        letter_score = score[i]
        word_score += letter_score

    return word_score

print scrabble_score("pie")

also, on codecademy version of your code:

  scrabble_score("pie")

there is indent on this line, placing the function call inside the function


#5

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