0

Hello, I am trying to sum lists if a condition is met, not working, not sure why, I end

up with PN=[0,0,0,0,0,0,0,0] which is it's initial condition and should be PN=[1,1,1,1,0,1,1,1]

as PN0 and PN1 satisfy the condition PNi.count(1)<2, so PN+PN0+PN1 = [1,1,1,1,0,1,1,1].

Thanks.

>>> PN0=[0,0,1,1,0,1,0,1]
PN1=[1,1,0,0,0,0,1,0]
PN2=[0,0,0,0,1,0,0,0]
PN=[0,0,0,0,0,0,0,0]
NULL==[0,0,0,0,0,0,0,0]
for i in range(3):
    if PNi.count(1) < 2:
        PN=[sum(pair) for pair in zip(PN, PNi)]
        print('Yes')
    else:
        PNi=NULL
        print('No')

Edited by capson: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by capson
0

Variable PNi is uninitialized and variables PN0, PN1 and PN2 are unused.
Comparison of NULL fails and it is not in statement.

PN0=[0,0,1,1,0,1,0,1]
PN1=[1,1,0,0,0,0,1,0]
PN2=[0,0,0,0,1,0,0,0]
PN=[0,0,0,0,0,0,0,0]
NULL==[0,0,0,0,0,0,0,0]
for i in range(3):
    if PNi.count(1) < 2:
        PN=[sum(pair) for pair in zip(PN, PNi)]
        print('Yes')
    else:
        PNi=NULL
        print('No')
"""Output:

Traceback (most recent call last):
  File "D:/test/PN.py", line 5, in <module>
    NULL==[0,0,0,0,0,0,0,0]
NameError: name 'NULL' is not defined
>>> """

Also:

>>> PN0=[0,0,1,1,0,1,0,1]

>>> PN0.count(1)
4

So it does not fulfill condition count(1)<2

Edited by pyTony: n/a

0

Thank you, sorry about my lack of attention to the details.

Edited by capson: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.