[英]I am getting compilation error in if -else program in python .The code is written in Python 3, can anyone help me
n = int(input().strip())
if N % 2 != 0:
print "Weird"
else:
if N >= 2 and N <= 5:
print "Not Weird"
elif N >= 6 and N <= 20:
print "Weird"
elif N > 20:
print "Not Weird"
##if else problem in python 3
from the print statement without paranthesis, it seems the code you are showing is python2, partially compatible with python3.从没有括号的打印语句中,您显示的代码似乎是 python2,与 python3 部分兼容。
Besides, as mentionned, the take care of the case sensitivity for symbols like variables and functions.此外,如前所述,注意变量和函数等符号的大小写敏感性。
I think the problem is that you named you variable n.我认为问题在于您将变量命名为 n。 But you use it with a capital N. Python is case-sensitive so you have to keep everything the same.
但是您将它与大写 N 一起使用。 Python 区分大小写,因此您必须保持所有内容相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.