Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (12.7k points)

Consider the below string test

test = raw_input("enter the test") 

print test

It works fine in Python 2.x

In python 3.x, I do:

test = input("enter the test") 

print test

When I give input string sdas, I get the following error message

Traceback (most recent call last):

 File "/home/ananiev/PycharmProjects/PigLatin/main.py", line 5, in <module>

    test = input("enter the test")

 File "<string>", line 1, in <module> 

NameError: name 'sdas' is not defined

1 Answer

0 votes
by (26.4k points)

You're executing your Python 3 code with a Python 2 mediator (interpreter). On the off chance that you weren't, your print explanation would hurl a SyntaxError before it at any point incited you for input. 

The outcome is that you're utilizing Python 2's input, which attempts to eval your information (apparently sdas), finds that it's invalid Python, and bites the dust

Want to become an expert in Python? Join the python course fast!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...