indented block,应该怎么办?|indentationerror:expected an
来源:人文屋 本文已影响2.38W人
来源:人文屋 本文已影响2.38W人
这段代码完全没有问题,可能是你编辑器的问题,导致缩进对不上位置,另外我改写了下你的程序 ====================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
原因在于“:”后面的语句需要进行缩进
你的代码应该不全吧。凡是循环内部都要缩进1个空格。如果你if else缩进了,但是while也是循环,也需要缩进!所以while内部的if里需要缩进2个空格。你的错误就是循环没有加空格引起的。 #!/usr/bin/pythonimport osls=os.linesepfname = raw_inpu
将print语句缩进后即可正确输出a的值了
这段代码完全没有问题,可能是你编辑器的问题,导致缩进对不上位置,另外我改写了下你的程序 ====================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!
这段代码完全没百有问题,可度能是你编辑器的问问题,导答致缩进对不上位置,另外我改回写了下你的程序答
====================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/pythonimport 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追答他肯定要多留一行啊,要不你要是还要打代码不就不能了,没有返回代码他就执行了嘛,
failed的解决方法是什么|getthreadcontext
version of the rutime怎么办|XP系统出现unable to find a
a problem has been detected(电脑蓝屏)
软件安装错误Command line option syntax error
win7总提示internet explorer 已停止工作应该怎么办
explorer阻止了此网站安装activex控件应该怎么办|internet
version of runtime to的方法|解决unable to find a
out of date。killing的解决办法|adb server is
paperwhite不转格式看doc,pdf,txt等文件|kindle
torrentkitty search engine应该怎么用
proper boot device如何解决|电脑提示reboot and select
解决command line option syntax error终极方法是什么
Bundle(Eclipse)下载安装|Android开发环境ADT
nokeyboarddetected是什么意思
proper boot device|开机显示reboot and select
cad激活问题:could not get debug privilege如何解决
孩子反应慢该怎么办
Excel中Randbetween函数的使用方法
应该怎么解决|thunderplatform。exe-损坏的图像
vivox5l反应慢应该怎么办
岔气应该怎么办?
脚臭应该怎么办
classnotfoundexception是什么异常
负债人应该怎么办 负债人应该怎么做
iphone6s出现此apple id尚未在itunes store怎么使用
radeonsettingshostapplication已停止工作
defender smartscreen|关闭 win10
save mode|怎么解决屏幕显示entering power
launching installer应该怎么办|安装时出现 error
invocationtargetexception是什么异常
打印提示缺少ocr a extended等字体应该怎么办
operatingsystemnotfound什么意思
windows modules installer worker cpu占用率高怎么办
the best playwright in england主要讲了什么
excel中randbetween函数该怎么使用
excel中randbetween公式怎么用
the JNIshared library|怎么解决Failed to load
Excel中Randbetween函数怎么用
怎么使用winebottler在mac上安装explorer
is not available处理|The requested resource
电脑invalid partition table怎么办