“预期缩进的块”错误,但是有缩进的块

时间:2019-05-20 01:23:25

标签: python-3.x

我收到语法“预期缩进块”错误,但是肯定有缩进块。我已经检查并重写了一百万遍。

#Game loop:
while True: #The error is occurring here
    load()
    #Main game loop:
    while game_over == False:
            load_stage()
    #Win screen and restart option:
    print('\n**********************************************')
    print ('Congratulations! You Won!')
    answer = input('Would you like to restart?\nIf so type \'restart\'.')
    if answer == 'restart':
        restart()
        save()
    else:
        pass

1 个答案:

答案 0 :(得分:0)

尝试:

#Game loop:
while True: #The error is occurring here
    load()
    #Main game loop:
    while game_over == False:
        load_stage()
    #Win screen and restart option:
    print('\n**********************************************')
    print ('Congratulations! You Won!')
    answer = input('Would you like to restart?\nIf so type \'restart\'.')
    if answer == 'restart':
        restart()
        save()
    else:
        pass

由于缩进不一致导致出现错误,这意味着您的程序没有一致的缩进方案。通常,建议使用4个空格(其中空格=单个空格键)表示缩进的块。

如果您的程序交替使用Tab和空格进行缩进,也会出现不一致的情况。