2017-05-28 7 views
-3

を期待私はプログラミングに新しいです、私は、端末を使用して、このPythonプログラムを実行しようとエラーになった:File "abc1234.py", line 9 time.sleep(3) IndentationError: expected an indented block ^ファイル「abc1234.py」、9行目time.sleep(3)^ IndentationError:インデントブロック

import webbrowser 
import time 
time_total=3 
time_count=0 
print (" the current time is " +time.ctime()) 
while(time_count<time_total): 
time.sleep(3) 
webbrowser.open("https://www.youtube.com/results?search_query=raabta+song+deepika") 
time_count= time_count+1 

答えて

1

あなたはそれがあなたのエントリをオフに基づいてフォーマットする方法わかりません。 しかし、あなたのコードは次のようになります。

import webbrowser 
import time 
time_total = 3 
time_count = 0 
print (" the current time is " + time.ctime()) 
while(time_count < time_total): 
    time.sleep(3) 
    webbrowser.open("https://www.youtube.com/results?search_query=raabta+song+deepika") 
    time_count = time_count + 1 

あなたは、whileブロック内のすべてのコードをインデントしなければなりません。あなたは、行9にtime.sleep(3)を正しく字下げしていないはずです。通訳者は、のコロンの後に少なくとも1つのインデントされた行があり、ループはです。

+0

そのコードが機能しました。しかし、私はテキストエディタ "TextWrangler"を使用していますが、whileループを使用している間は手動で空白を追加する必要があります。whileループの中では、whileループの中で、ループ – Richa

+0

おそらくタブキーを使ってみることはできますか?しかし、私は、Python言語のサポートがあれば、環境設定のどこかで、自動インデントを有効にして4つのスペースにすることができると思います。私はTextWranglerを個人的に使用していないので、確かではありません。 –

+0

その作品..ありがとう@ドル - ロン – Richa

0

インデントなしでネストしたコードを記述しているからです。
は、ここではPythonでどのように動作するかです:

import webbrowser 
import time 
time_total=3 
time_count=0 
print (" the current time is " +time.ctime()) 
while(time_count<time_total): 
    time.sleep(3) 
    webbrowser.open("https://www.youtube.com/results?search_query=raabta+song+deepika") 
    time_count= time_count+1 
関連する問題