简体   繁体   English

我该如何解决这个我似乎找不到的缩进错误?

[英]How can i fix this Indentation Error I cant seem to find?

I keep getting a indentation error when adding a blit call to almost the end of this code, or anything else.将 blit 调用添加到几乎这段代码的末尾或其他任何地方时,我总是收到缩进错误。 I've been looking for the problem for over an hour but I can't find it.我一直在寻找问题一个多小时,但我找不到它。 Could somebody take a look at it, please?有人可以看一下吗?

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
      
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                speler_speed -= 6
            if event.key == pygame.K_DOWN:
                speler_speed += 6
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_UP:
                speler_speed += 6
            if event.key == pygame.K_DOWN:
                speler_speed -= 6
    
    bal_animatie()
    player_animation()
    computer_ai()
    screen.fill(bg_color)
    pygame.draw.rect(screen, wit, player)
    pygame.draw.rect(screen, wit, computer)
    pygame.draw.ellipse(screen, wit, ball)
    pygame.draw.aaline(screen, wit, (screen_width /2, 0),(screen_width / 2, screen_height))
    speler_text = font.render(f'{speler_score}',False,wit)
    screen.blit(speler_text,(screen_width / 2 + 25, screen_height / 2 -15))
    computer_text = font.render(f'{computer_score}',False,wit)
    screen.blit(computer_text,(screen_width / 2 - 40, screen_height / 2 - 15))

In a similar case, I was having a super difficult time finding out where the indentation was wrong in one of my code.在类似的情况下,我很难找出我的一段代码中缩进错误的地方。 If you are by chance using a bad editor (which doesn't support python), it wouldn't take care of indentations.如果您偶然使用了一个糟糕的编辑器(不支持 python),它不会处理缩进。
For python, a tab space and 4 spaces are not considered the same check each line to see if there is a combination of tabs and spaces used.对于 python,一个制表符和 4 个空格不被认为是相同的检查每一行以查看是否使用了制表符和空格的组合。
And make sure either all are spaces or all are tabs.并确保全部为空格或全部为制表符。 'd suggest you re indent all lines with tabs, and that should fix your issue.建议您重新缩进所有带制表符的行,这应该可以解决您的问题。

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

相关问题 如何解决 4 行的缩进错误? - How do I fix the indentation error of 4 line? 我的乌龟代码有一个错误,我似乎无法解决 - My turtle code has an error i cant seem to fix at the end of it 如何修复缩进错误?当我要填充 colors - How can I fix indentation Error?When I am going to fill colors 我似乎无法在我的代码中修复这些错误 - I cant seem to fix these erros in my code 如何修复错误无法划分 int 和 str,我无法修复它 - how to fix error cant divide int and str, i cant fix it 如何解决 Python 3 中的这个缩进错误? - How can I solve this indentation error in Python 3? 我似乎无法准确地得到它,我正在得到阶乘,但似乎无法找到一种方法来放入组合公式 - i can not seem to get it exactly, i am getting the factorials but cant seem to find a way to put in the combination formula 在 Python 中创建 class 时如何修复缩进错误? - How do I fix indentation error when creating a class in Python? 正在发生缩进错误,我似乎看不到是什么导致了错误 - Indentation-Error is occurring and i can't seem to see what is making the error 我无法使用 pip install 获得工作室代码来安装 dotenv。 错误找不到模块,请问我该如何解决? - I cant get studio code to install dotenv with pip install. Error cant find module, how do I fix it please?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM