2017-10-23 13 views
-1

docxという単語のテーブルと行を数えるためのスクリプトです。私の質問は、条件が失敗に終わるまでの私の印刷ステートメントの印刷はなぜですか。pythonで複数回印刷する関数を印刷

from docx import Document 
doc = Document("sample2.docx") 
i = 0 
for t in doc.tables: 
    for ro in t.rows: 
     if ro.cells[0].text=="Test Type" and (ro.cells[2].text=="Black Box" or ro.cells[2].text=="Black-Box"): 
      i=i+1 
print("Total Black Box Tests are: ", i) 

j=0 
for table in doc.tables: 
    for row in table.rows: 
     if row.cells[0].text=="ID": 
      j=j+1 
      print("Total no of Tables:", j) 

が私を助けて:私は

enter image description here

はここに私のコードは、あなたの参考のために画像を添付しました。ありがとう!最後のprint文のインデントと

+6

をお試しください! 0インクリメントのレベルでプリントを移動してください。 –

答えて

1

問題 だけインデントの問題この

from docx import Document 
doc = Document("sample2.docx") 
i = 0 
for t in doc.tables: 
    for ro in t.rows: 
     if ro.cells[0].text=="Test Type" and (ro.cells[2].text=="Black Box" or ro.cells[2].text=="Black-Box"): 
      i=i+1 
print("Total Black Box Tests are: ", i) 

j=0 
for table in doc.tables: 
    for row in table.rows: 
     if row.cells[0].text=="ID": 
      j=j+1 
print("Total no of Tables:", j) 
+0

@Arun Basker:それはあなたの問題を解決しましたか? –