+ 4

How to find the sum of all even integers in a list of numbers in python

.

21st Sep 2020, 4:08 PM
deepak Kumar
deepak Kumar - avatar
8 Respuestas
+ 4
deepak Kumar , It's common when asking a question about help for coding to show the own attempt first. But as there are already some solutions given, I will also throw my hat in the ring: l = [1,4,7,10,13,16] print(sum([i for i in l if i % 2 == 0]))
21st Sep 2020, 4:41 PM
Lothar
Lothar - avatar
+ 3
Arshia , the task was to sum all even integers from a list. Your code just prints the even integers. That is a good start. Try to add the functionality to sum these values. 👍
23rd Sep 2020, 3:57 PM
Lothar
Lothar - avatar
+ 2
Specify a relevant language in your tags please (replace the dot with a language name), proper tags improves context clarity 👍
21st Sep 2020, 4:10 PM
Ipang
+ 2
That's odd... SoloLearn problem solved! https://code.sololearn.com/c9mztWPbZn2n/?ref=app
22nd Sep 2020, 4:19 PM
Ogunleke Samuel Ayomide
Ogunleke Samuel Ayomide - avatar
+ 1
Mirielle[ InAcTiVe ] you have to write i&1, not i&2.
21st Sep 2020, 4:58 PM
R_3-dr
R_3-dr - avatar
+ 1
for i in list: if i % 2 == 0: print(i)
23rd Sep 2020, 2:42 PM
Arshia
Arshia - avatar