Script(Python) Doesn't allow inputs?


#1

I just started learning how to code on codeacademy, and one of the things you have to make there is a pig latin translator.

I tried making it on Atom today, and got this error:

Traceback (most recent call last):
  File "/home/musse/Programming/Python/Tests/aowdjaoiwjd.py", line 5, in <module>
    word1 = raw_input("Please enter the word you desire to translate:")
NameError: name 'raw_input' is not defined
[Finished in 0.326s]

This is my code:

# The pig latin translator

pig = "ay"

word1 = raw_input("Please enter the word you desire to translate:")
if len(word1) > 0 and word1.isalpha():
    word2 = word1[1]
    word3 = word1 + word2 + pig
    word3 = word3[1:len(word3)]
    print(word3)

else:
    print("The word you've enter is not accepted. Please try another one.")

Thanks!!


#2

No. This question has been asked a lot, so you will find plenty of good answers on how to get around that:

https://discuss.atom.io/search?q=python%20input

#3

raw_input() is Python 2 syntax, so this is what you get when you use a Python 3 interpreter.

Always remember:

Python 2: input() == Python 3: eval(input())
Python 2: raw_input() == Python 3: input()


#4

@seanmusse To clarify: your code is failing because your syntax is the wrong version of Python for the interpreter, but the script package also doesn’t allow for inputs.


#5

I had tried it using input() but got the same result, but thank you! :slight_smile:


#6

Both of them give the same error :confused:


#7

Thank you!