+ 2

tic_tac_toe error

i just wrote this code and after a lot of debugging😧 i made it work well in Python 2 But when i enter any character except for the numbers then it pops NameError, I added that in the exception too but still it pops nd the code stops when i hit a character The code is here👇 https://code.sololearn.com/cLu30FboF4D0/?ref=app

30th Dec 2017, 3:30 PM
Akhil Manchanda
Akhil Manchanda - avatar
3 ответов
+ 1
python 2 input is a function that combine with eval function. which mean, it will execute the command just like exec or eval. now try this in python 3 exec(input("what: ")) and you type "import os" now you really importing os module. using input in python2 is like a security hole. solution : use raw_input("answer: ") it will return normal string. or you can do import __future__
31st Dec 2017, 1:40 PM
Kevin AS
Kevin AS - avatar
+ 1
oh sorry, __future__ for print function. for input, use import builtins. than you will able to use normal input like in py3 actually its funny using input in python2. input("answer: ") type exit(). :v edit: source: http://hplgit.github.io/primer.html/doc/pub/input/._input-solarized010.html
1st Jan 2018, 10:24 AM
Kevin AS
Kevin AS - avatar
0
u mean import__future__input ?
1st Jan 2018, 9:28 AM
Akhil Manchanda
Akhil Manchanda - avatar