+ 5

Can you please explain the output of this code?

l = [] for i in range(17): l.append(i * 3) m = [x&1 for x in l] print(sum(m) Answer is 8

9th Mar 2020, 7:49 AM
APC (Inactive for a while)
APC (Inactive for a while) - avatar
2 Answers
+ 8
All JUMP_LINK__&&__Python__&&__JUMP_LINK Challenges are welcomed đŸ€– try to decode every single logic and step by line by line. And try to trace that out at paper that will give you an simple idea about working of the code. Here in past similar questions is asked try to use searchbar for that too https://www.sololearn.com/Discuss/1784343/?ref=app
9th Mar 2020, 7:58 AM
MsJ
MsJ - avatar
+ 3
l = [] for i in range(17): l.append(i * 3) print ("This is l:", l, sep = "\n") m = [x & 1 for x in l] print("\nThis is m:", m, sep = "\n") print(sum(m)) I just add some print works there to show the contents of list <l> and <m>. I guess you'll get the idea once you see what's inside list <m>.
9th Mar 2020, 8:05 AM
Ipang