[英]Indention issue in Python IDLE
空閑配置設置為
indentation width - 4 spaces
key set - IDLE classic windows
at startup - Open shell window
paragraph reformat width (in characters) - 70
我打開python IDLE,我在外殼程序窗口中。 我單擊文件>新文件。 我現在在文本編輯器中。 我寫了一行代碼。 語法是什么都沒關系。 當我按下鍵盤上的“輸入”按鈕時。 而不是下降到下一行並處於適當的位置。 閃爍的小東西向您顯示頁面上您在頁面中間的位置...
number = float(input('what is your number? ')
name = input('what is your name? ')
name = input('what is your name?')
this is where it indents to
it doesnt matter the syntax
number = int(input('what is your number?')
if number > 5
print (""" I am only using the enter key to
go to the next line""")
else:
print('this is what it does')
即使是雙倍行距,它也不應該是這樣嗎?
number = int(input('what is your number?')
if number < 5555
print (' helloe')
else:
print('..............')
您需要確保您的括號匹配。 在您的示例中,第一行缺少一個')'。
number = float(input('what is your number? ') ) # this last parenthesis is missing in your example
name = input('what is your name? ')
該代碼可能不會運行。 您應該養成在開始表達式時始終直接寫右括號的習慣。 這樣,您就知道它們已經匹配。
之所以會產生奇怪的縮進,是因為在沒有右括號的情況下,編輯器認為下一行是上一個表達式的一部分,即
number = float(input('what is your number? ')
# notice how the indentation is right below
# the opening parenthesis
)
name = input('what is your name? '
# notice how this indentation has a
# a different position
)
您在以下方面有誤:
if number > 5
正確的是:
if number > 5:
並且您寫道:
name = input('what is your name? ')
但您應該寫:
name = input('what is your name? ')
沒有所有的空間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.