突然之间,在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/