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')

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.