Ahoy! (or Should I Say Ahoyay!) - Whats wrong with my code?

<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.>

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>

```python

pig = ‘“Pig Latin”’
print (pig)
words = eval(input(‘Enter word’))
first = words[0]
pyg =
for x in range(1,len(words)):
pyg.append(words)

pyg.insert(len(words),first)
pyg.append(‘ay’)
words = ‘’.join(pyg)
print (words)

<do not remove the three backticks above>

This doesn’t seem to be part of the lesson, so, what are you trying to achieve? what version of python are you using? What is the problem you experience?

I’m using python3.
The program doesn’t show any error when running on my machine, but when submitting and running, on the website, it gives this error

Traceback (most recent call last):
File “python”, line 3, in
File “”, line 1, in
NameError: name ‘python’ is not defined

1 Like

i have more questions, why do you use eval()?

in python2 we had input() and raw_input(), but in python3 raw_input got renamed to input and the old input of python2 got removed.

to get the same effect of python2 input in python3, you could use eval(input()), but why would you?

so in other words, if you want to run this code on codecademy (which is python2), remove eval() since python2 input() equals python3 eval(input())

pig = '"Pig Latin"'
print (pig)
words = input('Enter word')
first = words[0]
pyg = []
for x in range(1,len(words)):
    pyg.append(words[x])

pyg.insert(len(words),first)
pyg.append('ay')
words = ''.join(pyg)
print (words)

Same error even after removing eval…
I accidentally left it on there

from the python2 input docs:

This function does not catch user errors. If the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation.

why use input? this means if the user enters something, it would be seen as variable. the docs (docs - input) recommend to use raw_input for prompting the user

But I’m coding using a python3 environment, so raw_input doesn’t work over there…
Is there some alternative available for python3?

And, I found why I couldn’t proceed ahead…
I had done the whole program and pasted it in part “01” which expects the user to just print “Pig Latin”
Hence I couldn’t submit the code.

Apart from the submission error, the doubt for what to use in python3 in place of raw_input??

python2 -> raw_input()
python3 -> input()

python2 raw_input has become input in python3

So, since this code which works fine on my machine is throwing an error when on the website, I’m presume that the code is being executed using python2??
Which means I’d have to use raw_input so I dont get that error?

no, that is why i am telling you that codecademy is using python2

in python2, yes, use raw_input.

Umm, sorry. Thank you so much for the help…

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