如何为X行打印循环标签?

时间:2019-06-07 11:09:59

标签: python

我需要在样品旁边打印标签。 我有96个样品(线)来自交替批次。我想在前96行旁边打印标签“ 1”,然后在后96行旁边打印标签“ 2”,然后再打印1,依此类推。 (我将来自平板测定的机器读数的数据汇总到垂直列表中)

我试图让计数器计数到96,然后更改数字,但是当然只能在前两批中起作用。如何处理x个样本?

j = 0
print("Value", "seq", "plate", sep = "\t")
for i in range(0,len(first_line),2):
    if j <= 96:
        plate = 1
    else:
        plate = 2
    print(first_line[i], sequence[j], plate, sep="\t")
    print(first_line[i+1], sequence[j], plate, sep="\t")
    print(second_line[i], sequence[j], plate, sep="\t")
    print(second_line[i+1], sequence[j], plate, sep="\t")
    j += 1

我想要得到什么:

        Value   seq             plate
line 95 1.141   EKWAFHQAWIEAA   1
line 96 1.115   GPEAWAAAAFWEI   1
line 97 1.112   LPWFDKAABFWAA   2
line 98 1.181   GSEGESAWAAAWD   2
...
line 272 1.111  EWFIUGHAIWDIW   1
line 273 1.911  AWFNAWAIWFAAW   1

1 个答案:

答案 0 :(得分:1)

这里是一个示例,您必须为用例弄清楚。您需要使用数字的模数,例如96。假设我必须先获得8号车牌,然后获得2号车牌,再获得1号车,依此类推。因此,请参见下文:

Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
    Call CheckChild(TreeView1, Node) 'perform check on child nodes
    'CheckChildren Node 'Call subroutine
End Sub


Private Sub CheckChild(Tree As TreeView, CurrentNode As Node)
    Dim ParentIndex 'used to find out the index of the parent node from the child node that was clicked
    Dim CheckChecked As Integer 'Used to decide whether or not parent is to be checked
    Dim j As Integer 'Counter
    On Error Resume Next

    If CurrentNode.Checked = True Then 'If node is checked then check parent node ONLY if ALL child nodes are checked
        If Tree.Nodes.item(CurrentNode.Index).Checked = True Then 'If "My Node"(My Node's Index) is checked then
            ParentIndex = Tree.Nodes.item(CurrentNode.Index).Parent.Index 'locate index of parent node
            For j = 1 To Tree.Nodes.item(ParentIndex).Children 'run loop to find out which child nodes
                If Tree.Nodes.item(ParentIndex + j).Checked = False Then 'are checked and which are not...

                    CheckChecked = CheckChecked + 0 'unchecked and 1 for checked, add to
                ElseIf Tree.Nodes.item(ParentIndex + j).Checked = True Then 'previous value  
                    CheckChecked = CheckChecked + 1
                End If
            Next j

            If CheckChecked = Tree.Nodes.item(ParentIndex).Children Then 'if the number of checked nodes is equal
                Tree.Nodes.item(ParentIndex).Checked = True 'to number of child nodes then all child
            Else 'nodes are checked so check parent node
                Tree.Nodes.item(ParentIndex).Checked = False
            End If
        End If
    ElseIf CurrentNode.Checked = False Then 'if the current node is unchecked then
        ParentIndex = Tree.Nodes.item(CurrentNode.Index).Parent.Index 'uncheck the parent node as ALL child nodes
        Tree.Nodes.item(ParentIndex).Checked = False 'must be checked to before the parent node is checked
    End If

    'To enable and disable checkboxes based on Parent Node CheckBox
    Dim i As Integer, nodX As Node
    If CurrentNode.Children <> 0 Then 'If node has children
        Set nodX = CurrentNode.Child 'Catch first child
        For i = 1 To CurrentNode.Children 'Loop through each child
            nodX.Checked = CurrentNode.Checked 'Set as checked
            'CheckChildren nodX 'Check to see if this node has children
            Set nodX = nodX.Next 'Catch next child
        Next 'Loop
    End If
End Sub

输出为:

for a in range(1,50):
    if (int(a/9)%2)==0:
        print(f'At index {a}, plate is 1')
    else:
        print(f'At index {a}, plate is 2')

请注意,对于所需的输出,我在模数中使用9。因此,我希望您能找出其余的情况。