簡體   English   中英

使用 elif 語句時出現無效語法錯誤(不是縮進錯誤)

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

應該是一個容易解決的問題。 如果您在下面看到我的代碼,那么讀取elif target_2.got_away == True:返回無效的語法錯誤。 我已經閱讀了關於此的其他帖子,所有提示都涉及在 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()

它正上方的行沒有第二個右括號。 我經常發現語法錯誤在發生后就被標記在行上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM