if two requirements in a multiple if statement are meet than the next time they are meet I want to check something else
<p>So this is the code I have right now.</p>

<pre><code>count1_1 = 0
previous_1 = False
for i in B:
    if B[i] % 10 == 1 and B[i + 2] % 10 == 3:
        if A[i] * A[i + 2] == 1:
            current_1 = i % 10 == 1
            if current_1 and previous_1:
                count1_1 += 1
            previous_1 = current_1
return count1_1
</code></pre>

<p>Right now this code counts every time that all the specified criteria are meet following the first time they are meet. I was wondering if anyone knows of a way I could modify the code so that when the code runs it first find the first number that meets these requirements:</p>

<pre><code>if B[i] % 10 == 1 and B[i + 2] % 10 == 3:
    if A[i] * A[i + 2] == 1:
</code></pre>

<p>and also has i % 10 = 1. Then instead of finding each time these requirements are meet, it will only add to a count if the next time these requirements are meet:</p>

<pre><code>if B[i] % 10 == 1 and B[i + 2] % 10 == 3:
    if A[i] * A[i + 2] == 1:
</code></pre>

<p>at that point i % 10 also has to be equal to 1. If it is not then I want the code to stop. </p>

<p>Essentially I want to add to a count only if all the requirement are meet in consecutive times that these requirements are meet:</p>

<pre><code>if B[i] % 10 == 1 and B[i + 2] % 10 == 3:
    if A[i] * A[i + 2] == 1:
</code></pre>

<p>EDIT:</p>

<p>In this code B is a range and this is A</p>

<p>[0, 1, 1, 1, 4, 1, 6, 1, 8, 9, 10, 1, 12, 1, 14, 15, 16, 1, 18, 1, 20, 21, 22, 1, 24, 25, 26, 27, 28, 1, 30, 1, 32, 33, 34, 35, 36, 1, 38, 39, 40, 1, 42, 1, 44, 45, 46, 1, 48, 49, 50, 51, 52, 1, 54, 55, 56, 57, 58, 1, 60, 1, 62, 63, 64, 65, 66, 1, 68, 69, 70, 1, 72, 1, 74, 75, 76, 77, 78, 1, 80, 81, 82, 1, 84, 85, 86, 87, 88, 1, 90, 91, 92, 93, 94, 95, 96, 1, 98, 99, 100, 1, 102, 1, 104, 105, 106, 1, 108, 1, 110]</p>

<p>When I run my code it should only add to count1_1 once because the only time all conditions are meet in consecutive times that the first two conditions are meet is at index ((71,73),(101,103)). When I run my code it returns count1_1 = 4 because the conditions are meet 4 times after the first time the condition is meet at index(1,3). I want to change my code so that the next time that (i and i + 2 = 1) if the remainder of their index in % 10 is not equal to 1 and 3 than it will look for the next time that all conditions are meet and if all conditions are meet then again after that, like at index ((71,73),(101,103)), than it will add to count1_1.</p>

<p>Hope that clears up the question a bit.</p>

<p>I think that I get it</p>

<pre><code>def my_count(A):
    count = 0
    previous=False
    for i in range(1, len(A)-2, 10):
        current =  A[i] * A[i + 2] == 1
        if previous and current:
            count += 1
        previous = current
    return count


data=[   0,   1,   1,   1,   4,   1,   6,   1,   8,   9,  #0
        10,   1,  12,   1,  14,  15,  16,   1,  18,   1,  #1
        20,  21,  22,   1,  24,  25,  26,  27,  28,   1,  #2
        30,   1,  32,  33,  34,  35,  36,   1,  38,  39,  #3
        40,   1,  42,   1,  44,  45,  46,   1,  48,  49,  #4
        50,  51,  52,   1,  54,  55,  56,  57,  58,   1,  #5
        60,   1,  62,  63,  64,  65,  66,   1,  68,  69,  #6
        70,   1,  72,   1,  74,  75,  76,  77,  78,   1,  #7
        80,  81,  82,   1,  84,  85,  86,  87,  88,   1,  #8
        90,  91,  92,  93,  94,  95,  96,   1,  98,  99,  #9
       100,   1, 102,   1, 104, 105, 106,   1, 108,   1,  #10
       110]

print(my_count(data)) # output: 1
</code></pre>

<p>first as B is a range over the length of A, or so I assume, and you want only the index that are <em>i mod 10 = 1</em>, then that can by simply using the 3 argument call of <a href="https://docs.python.org/3/library/functions.html#func-range" rel="nofollow"><code>range</code></a> as that condition is fulfilled every 10 number starting in 1, therefore there is no need to check that every time. (Also for a range starting in 0 its i-esimo element is also i so using any of those is the same). The rest part should be self explanatory.</p>

<p>Now, by arranging that example data as show above, you can clearly see that the index were they are consecutive is in [(1,3), (11,13)] not in [(71,73), (101,103)] as you claim </p>

python