代码如下:

result = input('give your result:')

if result == '4':
print ("result is 4")
elif result == '5':
print ("result is 5")
elif result == '6':
print ("result is 6")
else:
print ("result is wrong")

 运行结果如下:

=================== RESTART: C:/Users/公有制/Desktop/four.py ===================
give your result:4
result is wrong
>>>
=================== RESTART: C:/Users/公有制/Desktop/four.py ===================
give your result:4
result is 4
>>>
=================== RESTART: C:/Users/公有制/Desktop/four.py ===================
give your result:6
result is 6
>>>

可以发现,开始输入4,输出却是“result is wrong”,所以有点问题,问题是:if判断里面没有给4加‘’导致的,需要给它加一个单引号。

另外,由于python2和python3的兼容性问题,会出现Missing parentheses in call to 'print'的错误,原因是python3的编译器上编译python2的代码,因为Python3中print打印是要加括号的,不得不吐槽,python这兼容性有点差。