python-3.x - Python3 IndentationError : expected an indented block - should not throw this

标签 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

奇怪的是,它在之前工作得很好,而现在我又回到它的决定,在到期之前就搞砸了。帮助贴!

最佳答案

看一下前面的行:

for t in range(11):

它之后需要缩进的块(因此会出现错误)。如果您实际上不打算做任何事情,请编写pass:
for t in range(11):
    pass

关于python-3.x - Python3 IndentationError : expected an indented block - should not throw this,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29785722/

相关文章:

latex - 如何禁用 LaTeX 中特定部分的缩进?

django - 检索邻居的查询太慢

python-3.x - Webkit_server(从 python 的 dryscrape 调用)在访问每个页面时使用越来越多的内存。如何减少使用的内存?

python - 视频捕获后整个帧旋转

java - 我不断收到<identifier>预期错误

python - 处理 Tweepy api 返回的 420 响应码

c# - 有没有办法强制使用制表符而不是空格?

python - 在Python包中导入一个上两下一层目录的模块

php - JavaScript奇怪的错误:“意外的')'”

展开 html 标签后的 Vim 光标位置