0

ユーザー入力から Cheetah 経由でエクスポートするテーブルを作成して、レポートとして使用するテンプレートを作成しようとしています。「for j in range(1, numErrors):」ループの各反復を分離するのに問題があり、各連結の最初と最後にテーブル行タグを配置します。

table = ""
cells = ""
row = ""

numMeas = int(raw_input("Enter total number of measurements: "))
numMeas = numMeas + 1 #number of measurements compensated for iteration behavior
for i in range(1, numMeas):
    typeMeas = raw_input("Enter type of measurement "+str(i)+": ")
    numErrors = int(raw_input("Enter number of error sources: "))
    numErrors = numErrors + 1
    for j in range(1, numErrors): #builds dataSet from number of errors
        inputData = []
        inputData.append(typeMeas)
        description = raw_input("Enter source of uncertainty "+str(j)+": ")
        inputData.append(description)
        estUncert = raw_input("Enter estimated uncertainty "+str(j)+": ")
        estUncert = float(estUncert)
        inputData.append(str(estUncert))

        for i in inputData:
            cell = "<td>"+str(i)+"</td>"
            cells += cell

    table = "<tr>"+cells+"</tr>"+"\n"

print table

Current output:
<tr><td>mass</td><td>scale</td><td>1.0</td><td>mass</td><td>human</td><td>2.0</td>               <td>temp</td><td>room</td><td>3.0</td><td>temp</td><td>therm</td><td>4.0</td></tr>

Desired output:
<tr><td>mass</td><td>scale</td><td>1.0</td></tr>
<tr><td>mass</td><td>human</td><td>2.0</td></tr>
<tr><td>temp</td><td>room</td><td>3.0</td></tr>
<tr><td>temp</td><td>therm</td><td>4.0</td></tr>
4

1 に答える 1

1

おそらく次のようにする必要があると思います。

table = ""
cells = ""
row = ""

numMeas = int(raw_input("Enter total number of measurements: "))
numMeas = numMeas + 1 #number of measurements compensated for iteration behavior
for i in range(1, numMeas):
    typeMeas = raw_input("Enter type of measurement "+str(i)+": ")
    numErrors = int(raw_input("Enter number of error sources: "))
    numErrors = numErrors + 1
    inputData = []
    for j in range(1, numErrors): #builds dataSet from number of errors
        inputData.append(typeMeas)
        description = raw_input("Enter source of uncertainty "+str(j)+": ")
        inputData.append(description)
        estUncert = raw_input("Enter estimated uncertainty "+str(j)+": ")
        estUncert = float(estUncert)
        inputData.append(str(estUncert))
    cells = ''
    for i in inputData:
        cell = "<td>"+str(i)+"</td>"
        cells += cell

    table += "<tr>"+cells+"</tr>"+"\n"

print table
于 2013-06-18T22:43:26.090 に答える