简体   繁体   English

使用 elif 语句时出现无效语法错误(不是缩进错误)

[英]I am getting an invalid syntax error when using elif statement (Not an indentation error)

Should be an easy issue to solve.应该是一个容易解决的问题。 If you see my code below, the line that reads elif target_2.got_away == True: is returning an invalid syntax error.如果您在下面看到我的代码,那么读取elif target_2.got_away == True:返回无效的语法错误。 I have read other posts on this an all tips regard either not using an 'IF' statement before the elif or wrong indentation, which I believe this to be neither.我已经阅读了关于此的其他帖子,所有提示都涉及在 elif 或错误缩进之前不使用“IF”语句,我认为这两者都不是。

def refresh_window():
  if len(target_sprites) > 0:
   window.blit(bgr, (0,0))
  if len(target_sprites) == 0:
    window.blit(winner, (0,0))
  if target_1.got_away == True:
    window.blit(loser, (0,0)
  elif target_2.got_away == True:
    window.blit(loser, (0,0))
  elif target_3.got_away == True:
    window.blit(loser, (0,0))
  elif target_4.got_away == True:
    window.blit(loser, (0,0))
  elif target_5.got_away == True:
    window.blit(loser, (0,0))
  elif target_6.got_away == True:
    window.blit(loser, (0,0))
  player_sprites.draw(window)
  target_sprites.draw(window)
  for item in all_bullets:
    pygame.draw.rect(window, BLUE, (item['x']-5, item['y']-5, 10, 10))
    b_hitbox = (item['x']-10, item['y']-10, 20, 20)
    pygame.draw.rect(window, BLUE, b_hitbox, 2)
  pygame.display.update()

The line right above it doesn't have a second closing parenthesis.它正上方的行没有第二个右括号。 I often find that syntax errors are flagged on the line after they occur.我经常发现语法错误在发生后就被标记在行上。

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

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