+ 2

You want to take a list of numbers and find the sum of all of the even numbers in the list. Ignore any odd numbers.

Please help me to solve this with python.

25th Mar 2022, 3:54 PM
Kalyani Khakal
Kalyani Khakal - avatar
20 Réponses
+ 1
num = [ 1, 2, 3, 4] for x in num: if x % 2 == 0: print(x+0)
26th Mar 2022, 10:11 PM
athaleyah weise
0
Your solution?
25th Mar 2022, 3:56 PM
A͢J
A͢J - avatar
0
Use for loop: Here is my solution: List = [ list of numbers] sums = 0 for i in List: if i % 2 == 0 : sums += i print(sums)
25th Mar 2022, 4:07 PM
Beh
Beh - avatar
0
It's not working.. invalid syntax.expected output is 278
25th Mar 2022, 4:17 PM
Kalyani Khakal
Kalyani Khakal - avatar
0
Kalyani Khakal I guess the problem is with Print function. Make sure that all the words in print() are lowercase. I forgot to fix it when i was writing.
25th Mar 2022, 4:26 PM
Beh
Beh - avatar
0
Ok
25th Mar 2022, 4:30 PM
Kalyani Khakal
Kalyani Khakal - avatar
0
It still not working,I think the problem is in 1st line
25th Mar 2022, 4:33 PM
Kalyani Khakal
Kalyani Khakal - avatar
0
Can i see your code?
25th Mar 2022, 4:35 PM
Beh
Beh - avatar
0
List = [1,2,3,4,5,6,7,8,9] sums = 0 for i in List: if i % 2 == 0 : sums += i print(sums)
25th Mar 2022, 4:41 PM
Kalyani Khakal
Kalyani Khakal - avatar
0
This code is working fine. I don’t know what is the problem. Here you can test it yourself: https://code.sololearn.com/cw7poVLUtep3/?ref=app
25th Mar 2022, 4:51 PM
Beh
Beh - avatar
0
Thank u for your help..
25th Mar 2022, 5:08 PM
Kalyani Khakal
Kalyani Khakal - avatar
0
No problem mate. :D
25th Mar 2022, 5:30 PM
Beh
Beh - avatar
0
Java
25th Mar 2022, 9:05 PM
shehab adlan
shehab adlan - avatar
0
You can use another list for storing even numbers within a loop the put that new list in the sum() function
26th Mar 2022, 12:53 PM
SSTech SS
0
Community organization and would
26th Mar 2022, 3:53 PM
Nimesh Patel
0
Use this code: l= [] for i in list_numbers: if i%2==0: l.append(i) else: pass print(sum(l))
26th Mar 2022, 4:05 PM
SSTech SS
0
Please help me to go further in my lessons in solo my heart finished and i can do anything just discussing
26th Mar 2022, 4:06 PM
SSTech SS
0
Better use numpy and sort and filter them then just simple addition will suffice
26th Mar 2022, 9:35 PM
Nanda Srikanth S K Nanda
Nanda Srikanth S K Nanda - avatar
0
Why to suffer, try this: a = list(range(26)) print(sum(filter(lambda x: x%2==0,a)))
27th Mar 2022, 12:09 PM
Ervis Meta
Ervis Meta - avatar
0
Code: 1. nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 2. sum = 0 3. for num in nums: 4. if(num%2==0): 5. sum = sum + num 6. print(sum) Explanation: 1. Initializes a list of numbers from 1 to 10 2. Initializes the value of sum to 0 3 & 4. Checks whether any value in the list is even 5. Adds these values together and stores them in the sum variable 6. Finally prints the sum
27th Mar 2022, 1:12 PM
Newt Strider
Newt Strider - avatar