當前位置:生活全書館 >

IT科技

> indented block,應該怎麼辦? indentationerror:expected an

indented block,應該怎麼辦? indentationerror:expected an

這段程式碼完全沒有問題,可能是你編輯器的問題,導致縮排對不上位置,另外我改寫了下你的程式 ====================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追答他肯定要多留一行啊,要不你要是還要打程式碼不就不能了,沒有返回程式碼他就執行了嘛,

標籤: indented block
  • 文章版權屬於文章作者所有,轉載請註明 https://shqsg.com/dianzi/xwq9x8.html