我在python的if-else程序中遇到编译错误。代码是用python 3编写的,有人能帮我吗 n=int(输入().strip()) 如果N%2!=0: 打印“怪异” 其他: 如果N>=2且N=6且N=20: 打印“不奇怪” ##python 3中的if-else问题

我在python的if-else程序中遇到编译错误。代码是用python 3编写的,有人能帮我吗 n=int(输入().strip()) 如果N%2!=0: 打印“怪异” 其他: 如果N>=2且N=6且N=20: 打印“不奇怪” ##python 3中的if-else问题,python,if-statement,Python,If Statement,我认为问题在于您将变量命名为n。但是你可以使用大写字母N。Python是区分大小写的,所以你必须保持一切不变 从没有paranthesis的print语句来看,您显示的代码似乎是python2,与python3部分兼容 或者使用python2解释器执行它(已弃用) 或者更改一些内容以使其符合python3 除此之外,如前所述,系统会考虑变量和函数等符号的大小写敏感度 n = int(input().strip()) if N % 2 != 0: print "Weird" e

我认为问题在于您将变量命名为n。但是你可以使用大写字母N。Python是区分大小写的,所以你必须保持一切不变

从没有paranthesis的print语句来看,您显示的代码似乎是python2,与python3部分兼容

  • 或者使用python2解释器执行它(已弃用)
  • 或者更改一些内容以使其符合python3
除此之外,如前所述,系统会考虑变量和函数等符号的大小写敏感度

  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