Python3 IndentationError:期望一个缩进块 - 不应该抛出这个

时间:2015-04-22 00:43:10

标签: python-3.x error-handling indentation

突然之间,在Textmate和Sublime没有问题编码之后,突然间我随机得到这些错误,IndentationError:期望一个缩进的块。

我知道这是一个很新手的错误。我没有更改文本编辑器的任何设置,标签设置为4个空格,我使用PEP8。这是代码:

menu_choice = True

while menu_choice != 'E' or menu_choice != 'e':
    menu_choice = input('Enter your choice >>>')

    if menu_choice == 'A' or menu_choice == 'a':

        newcar = add_car()
        car_list.append(newcar)
        print(newcar)

    elif menu_choice == 'B' or menu_choice == 'b':

        stats = car_stats(car_list)
        print(stats)

    elif menu_choice == 'C' or menu_choice == 'c':

        print('\n\nDistance    Car Speed   Ideal Speed  Engine speed\n')
        for car in car_list:
            for t in range(11):
                arg = newcar.travel_time(t), newcar.speed(t), newcar.ideal_speed(t), newcar.engine_speed(t)
                s = map(lambda x: '{:0.2f}'.format(x), arg)
                s = map(lambda x: '{:<12s}'.format(x),s)
                print(' '.join(s))

    elif menu_choice == 'D' or menu_choice == 'd':
        for car in car_list:
            for t in range(11):

    elif menu_choice == 'E' or menu_choice == 'e':
        break
    else:
        print('Bad input! Try again!')

它不喜欢这一行:

File "race.py", line 139
elif menu_choice == 'E' or menu_choice == 'e':
^
IndentationError: expected an indented block

奇怪的是它以前工作正常,现在我回到它决定在它到期之前搞砸了。帮助广告!!!

1 个答案:

答案 0 :(得分:0)

看看之前的一行:

for t in range(11):

它需要一个缩进的块(因此错误)。如果你真的想要什么都不做,请写pass

for t in range(11):
    pass