[英]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.