关闭→
当前位置:科普经验站>IT科技>indented block,应该怎么办? indentationerror:expected an

indented block,应该怎么办? indentationerror:expected an

科普经验站 人气:2.42W

这段代码完全没有问题,可能是你编辑器的问题,导致缩进对不上位置,另外我改写了下你的程序 ====================guess.py======== number = 23 while True: guess = raw_input('Enter an integer('q' for quit) : ') #'q' for quit if guess

python编写时报IndentationError:expected an indented block错误,这时候该怎么办呢?下面与大家分享解决方法

方法

编写Python代码时会遇到expected an indented block错误

这段代码完全没有问题,可能是你编辑器的问题,导致缩进对不上位置,另外我改写了下你的程序 ====================guess.py======== number = 23 while True: guess = raw_input('Enter an integer('q' for quit) : ') #'q' for quit if guess

indentationerror:expected an indented block,应该怎么办?

原因在于“:”后面的语句需要进行缩进

你的代码应该不全吧。凡是循环内部都要缩进1个空格。如果你if else缩进了,但是while也是循环,也需要缩进!所以while内部的if里需要缩进2个空格。你的错误就是循环没有加空格引起的。 #!/usr/bin/pythonimport osls=os.linesepfname = raw_inpu

indentationerror:expected an indented block,应该怎么办? 第2张

将print语句缩进后即可正确输出a的值了

这段代码完全没有问题,可能是你编辑器的问题,导致缩进对不上位置,另外我改写了下你的程序 ====================guess.py======== number = 23 while True: guess = raw_input('Enter an integer('q' for quit) : ') #'q' for quit if guess

indentationerror:expected an indented block,应该怎么办? 第3张

扩展阅读,以下内容您可能还感兴趣。

很简单的python程序有问题:错误提示:IndentationError:expected an indented block!

这段代码完全没百有问题,可度能是你编辑器的问问题,导答致缩进对不上位置,另外我改回写了下你的程序答

====================guess.py========

number = 23

while True:

guess = raw_input('Enter an integer(\'q\' for quit) : ')

#'q' for quit

if guess == 'q':

break

guess = int(guess)

if guess == number:

print 'Congratulations, you guessed it.'

break

elif guess < number:

print 'No, it is a little higher than that'

else:

print 'No, it is a little lower than that'

python入门,请帮忙看一下这个程序问题在哪里,IndentationError: expected an indented block。

你的e68a847a6431333363356630代码应该不全吧。凡是循环内部都要缩进1个空格。如果你if else缩进了,但是while也是循环,也需要缩进!所以while内部的if里需要缩进2个空格。你的错误就是循环没有加空格引起的。

#!/usr/bin/python

import os

ls=os.linesep

fname = raw_input("please input file name:n")

#get filename

while True:

 if os.path.exists(fname):

  print ("ERROR:'%s' already exists"%fname)

 else:

  break

#get file content (text)lines

all=[]

print("nEnter line('.'by itself to quit).n")

while True:

 entry=input('>')

 if entry=='.':

  break

 else:

  all.append(entry)

#write lines to file with proper line-ending

fobj=open(fname,'w')

fbj.writelines('%s%s'%(x,ls)for x in all)

fobj.close()

print('DONE')

#File "<input>", line 8

if os.path.exists(fname):

 print "ok"

Python中def的错误,IndentationError: expected an indented block

因为这里是给class定义方法,不是全局函数,所以应该空格。

python第二行有什么问题 IndentationError: expected an indented block

缩进问题吧

python for循环

兄弟,你眼神呢?print前边加4个空格or tab更多追问追答追问缩进了是这样,敲一下回车到了下一行,并没有打印执行的结果。

>>> for a in ['a','s','c']:

... print(a)

...追答兄弟,多打几个回车试试可好,你现在还在代码块里啊!!!其实咋俩水平差不多,我准备用Python做自动化渗透,刚开始准备学Ruby的,后来感觉这个比Ruby好点,就学这个了,你呢,追问我是初学者,不是print()之后敲回车会打印结果的嘛,就这个地方不行。感觉是版本或者环境问题。其他的都是好的。多谢了。追答没事没事,2.7好像也是一样的,找个IDE吧,比黒框框好用,追问莫名其妙,我在第二行的地方敲了一个回车,然后就执行。

>>> for a in ['a','b','c']:

... print(a)

...

a

b

c追答他肯定要多留一行啊,要不你要是还要打代码不就不能了,没有返回代码他就执行了嘛,

TAG标签:#block #indented #