pig = '"Pig Latin"' print (pig) words = eval(input('Enter word')) first = words 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)
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
i have more questions, why do you use
in python2 we had
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
pig = '"Pig Latin"' print (pig) words = input('Enter word') first = words 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.