识别错误

时间:2017-04-07 01:46:20

标签: python pygame command-prompt

我有错误,说" IndentationError:unindent与任何外部缩进级别都不匹配",我已经尝试使用命令并更改空格和标签但仍然,错误继续出现,我有尝试了所有我在论坛中阅读但错误仍然出现在同一部分,请帮助 错误部分: bullets.update()                ^ 代码:

    def update_bullets(bullets):
"""Update position of bullets and gets rid of old bullets"""
#Update bullet position
 bullets.update()

# Get rid of bullets that had dissapeared
    for bullet in bullets.copy():
        if bullet.rect.bottom <= 1:
            bullets.remove(bullet)
        print(len(bullets))

1 个答案:

答案 0 :(得分:2)

正确缩进的代码应如下所示:

def update_bullets(bullets):
"""Update position of bullets and gets rid of old bullets"""
    #Update bullet position
    bullets.update()

    # Get rid of bullets that had dissapeared
    for bullet in bullets.copy():
        if bullet.rect.bottom <= 1:
            bullets.remove(bullet)
        print(len(bullets))

Python代码始终需要适当的缩进。空白很重要(与C不同)!

我建议您查看this tutorial以获取有关Python的基本教程。