Why am I able to use a variable as I'm declaring it?


So, the translator is saying my code works and I can move on
but I don't understand why I am able to use the new_word variable
as I'm declaring it for the first time?

new_word = word[1:len(new_word)] + first + pyg

I'm expecting some kind of error during run-time at least. I'm not
too sure, new to Python

original = raw_input('Enter a word:')
pyg = "ay"

if len(original) > 0 and original.isalpha():
    word = original.lower()
    first = word[0]
    new_word  =  word[1:len(new_word)] + first + pyg
    print new_word
    print 'empty'


Hi, @devrockstar56314 ,

Refresh the page, and you will find that the code does not work anymore because of this statement ...

new_word  =  word[1:len(new_word)] + first + pyg

Until you refresh the page, Codecademy will remember the new_word variable from previous submissions, even if they were from previous exercises. Go back to the exercise where you originally defined new_word to recall some previous work. You will need to copy and paste the statement that initializes new_word before you make the call, len(new_word).


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