while循环的语法无效

时间:2018-03-20 19:48:36

标签: python while-loop

if rounds == 20:
    response2 = input("Ok the game has now finished. I hope you had fun playing because I sure did. If you want, type 'restart' to play again.")
    if response2.lower() == "restart":
        start_game()
    elif playerpoints >= 10:
        print("Wow you did quite well. Your score is " + str(playerpoints)
        (img = pygame.image.load('TrophyImage.png'))

        (pygame.init())
        (size = (1000, 1000))
        (screen = pygame.display.set_mode(size))
        (done = False)
        (clock = pygame.time.Clock())

        while not done:
            for event in pygame.event.get(): 
                if event.type == pygame.QUIT: 
                    done = True
            screen.fill(WHITE) 
            screen.blit(img,(0,0))
            pygame.display.flip() 
            clock.tick(60)
        pygame.quit()

我已经在代码的开头定义了颜色,因此它们不是问题。

我正在尝试加载一张我保存的奖杯图片。当我运行此程序时,它会显示无效语法,但不会突出显示任何内容。 I光束指针只是进入“未完成”,所以我猜其中存在问题。

1 个答案:

答案 0 :(得分:1)

您需要删除分配周围的括号。 (X = Y)需要X = Y。因为表达式上下文中不允许赋值。

>>> (X = Y)
  File "<stdin>", line 1
    (X = Y)
       ^
SyntaxError: invalid syntax
>>> X = Y