简体   繁体   English

我在 python 的 if -else 程序中遇到编译错误。代码是用 Python 3 编写的,谁能帮帮我

[英]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 部分兼容。

  • Either execute it with python2 interpreter (deprecated)使用 python2 解释器执行它(已弃用)
  • Or change a few stuffs to get it compliant to python3.或者更改一些东西以使其符合 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.

相关问题 为什么我收到 OmegaExpansion header 的 Python 模块错误。 谁能帮我? - why am i getting Python Module error for OmegaExpansion header. Can anyone help me? 谁能帮我解决运行这个tensorflow程序时遇到的错误 - can anyone help me in resolving the error which I am getting while running this tensorflow program 运行此 python 代码时出现错误。 错误是“ElementNotInteractableException”。 任何人都可以帮助我吗? - I am getting error while running this python code. The error is “ElementNotInteractableException”. Can any on help me out? 我的 python 代码出现错误,你能帮我修复它吗? - i am getting an error in my python code can you help me fix it? 谁能帮我解决我在Python 2.7中不断遇到的TypeError问题? - Can anyone help me with this TypeError I keep getting in Python 2.7? 运行时错误:谁能帮帮我? Python代码 - Runtime Error: Can anyone help me out? Python code 有没有人可以在这个 python 代码中帮助我? - is there anyone can help me in this python code? 谁能帮我解释这个python代码吗? - Can anyone help me explain this python code? 嗨,我有一个 python 脚本可以使用 openpyxl 处理 excel 数据,但是在 2500 行之后我收到 Memory 错误。 谁可以帮我这个事? - Hi, I have a python script to work with excel data using openpyxl ,but after 2500 rows i am getting Memory Error. Can anyone help me on this? 有人可以帮我优化下面的 python 代码吗,我在某些测试用例中遇到超时异常 - Can someone help me in optimising the below python code, I am getting timeout exception for some of the test cases
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM