提问人:Thibault de Villèle 提问时间:10/29/2015 最后编辑:Thibault de Villèle 更新时间:10/29/2015 访问量:46
Python - 从文件中获取缩进错误
Python - Getting an Identation error out of the file
问:
我正在尝试用python制作一个小程序,没有什么复杂的,但非常长。刚才,我修改了“if”语句的一个条件,然后通过 MacOS 终端运行它,因为它有一个 Python shell / IDLE(我不知道它在英文中是如何称呼的)。
我的文档正好有 456 行,我得到的“IndentationError”位于“第 457 行”,这是输出:
文件“/Volumes/my usb key/MAIN_0.3.py”,第 457 行
^
IndentationError:预期为缩进块
我真的不知道该怎么做,因为我的程序的最后一行都是评论。如果你想要一些代码,我会尽量为大家简单地(用英语)表达,但我想先知道在“终端”中运行它是否没有问题,因为它真的很奇怪。
编辑:这是一些代码:
#coding= utf-8
#here I put a lot of variables(38), which are all 'int' or 'randint(x, y)'
#then I define some functions, which are all calculus
#here is the main loop :
while (a!=10) and (b > 10):
function_a(a)
c=0
while (c != 1) and (b > 0):
while b != 0:
print "\n"
d=randint(0,20)
if 0 <= d <= 3: #commentary explaining my program for my buddies at school
b=function_b(b, e, f, g, h, i, j, a, k, l)
if b <= 0: #commentary
m += n
p += a_b
if p > 1000: #commentary
p -= 1000
k += 1
print " BRAVO !"
print " now", k
time.sleep(1)
b += b_levelup
e += e_levelup
f += f_levelup
print " you won", b_levelup, "points"
time.sleep(1)
print " you won", e_levelup, "points"
time.sleep(1)
print " you won", f_levelup, "points"
time.sleep(1)
print "\n"*2
if 3 < d <= 8: #commentary
b=function_b(b, e, f, g, q, r, s, a, k, t)
if b <= 0: #commentary
m += u
p += v
if p > 1000: #
p -= 1000
k += 1
print " BRAVO !"
print " now", k
time.sleep(1)
b += b_levelup
e += e_levelup
f += f_levelup
print " you won", b_levelup, "points"
time.sleep(1)
print " you won", e_levelup, "points"
time.sleep(1)
print " you won", f_levelup, "points"
time.sleep(1)
print "\n"*2
if 8 < d <= 14: #commentary
b=function_b(b, e, f, g, w, x, y, a, z, k, a_a)
if b <= 0: #commentary
m += n
p += a_b
if p > 1000: #commentary
p -= 1000
k += 1
print " BRAVO !"
print " now", k
time.sleep(1)
b += b_levelup
e += e_levelup
f += f_levelup
print " you won", b_levelup, "points"
time.sleep(1)
print " you won", e_levelup, "points"
time.sleep(1)
print " you won", f_levelup, "points"
time.sleep(1)
print "\n"*2
if 15 <= d <= 16:#commentary
a_c += 1
function_c()
if d == 17: #commentary
a_d += 1
function_d()
#boss commentary
if (d == 18) and (a_d == 0):
print " mkay"
time.sleep(2)
print " nope"
print " next door"
#commentary
if (d == 18) and (a_d >= 1):
print " arrived"
time.sleep(2)
print " wanna go ?"
print " yes - 1"
print " No - any other"
a_e=input(" ")
if a_e == 1:
#boss commentary
答:
1赞
user2357112
10/29/2015
#1
评论不是陈述,所以当你这样做时
if something:
# Comment
没有身体。这是一个语法错误。如果你想要一个什么都不做的占位符正文,这就是该语句的用途。if
pass
if something:
# Comment
pass
评论
nothing complicated, but extremely long
try
except
finally