Code works in one Python environments but has a syntax error in another -
this question has answer here:
- print syntax error python 3 [duplicate] 5 answers
please have @ following code
def numbertoname(number): if (number==3): return "three" elif (number==2): return "two" elif (number==1): return "one" else: return "invalid" print numbertoname(2) print numbertoname(3) print numbertoname(1) print numbertoname(1)
this code runs 100% fine in following online python environment - http://www.codeskulptor.org/#user11_hh0kvupnvp_0.py
but when use idle
shows syntax error invalid syntax
in line print numbertoname(2)
my python version 3.3.1
i have noticed issues well. example, in given url, can run print "hello"
, output, same generated error in idle unless type print ("hello")
what issue here? new python, please help!
edit
please note main question given code snippet
that because ide using python 3.x, , not python 2.x in online environment.
in python 2.x can use print("test")
or print "text"
.
in python 3.x need use print("test")
.
this because in python 2.x print keyword, , not function, while in python 3 function.
if change print functions this, run on both web application , ide.
print(numbertoname(2)) print(numbertoname(3)) print(numbertoname(1)) print(numbertoname(1))
Comments
Post a Comment