简体   繁体   English

IndentationError: 在 def 中需要一个缩进块

[英]IndentationError: expected an indented block in def

I know there are many questions on this subject but i can't really find solution.我知道关于这个主题有很多问题,但我真的找不到解决方案。 I get this error every time running code每次运行代码时都会出现此错误

def spy_game(nums):
    code = [0,0,7,'x']
    for num in nums:
        if num == code[0]:
            code.pop(0)

    return len(code) == 1

Every line is intended correctly IMO.每一行都是正确的IMO。

  File "C:/Users/Гио/PycharmProjects/python_course/Методы и функции/Задачи по работе с функциями.py", line 61
    def spy_game(nums):
    ^
IndentationError: expected an indented block

I believe the problem is that you have inconsistent tabs and spaces.我认为问题在于您的制表符和空格不一致。

Make sure you use only one of the above.确保只使用上述其中一种。

I think you must go for a online code formatter such as https://www.tutorialspoint.com/online_python_formatter.htm我认为您必须 go 用于在线代码格式化程序,例如https://www.tutorialspoint.com/online_python_formatter.htm

This will also show you the identation error if it actually exists in your code and then you can correct it.如果它确实存在于您的代码中,这还将向您显示标识错误,然后您可以更正它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM