0
Help(That’s Odd code coach problem )
I am having trouble with the first part of the code. The second part is easy( adding even numbers and retuning sum) 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. Task: Find the sum of all even integers in a list of numbers. Input Format: The first input denotes the length of the list (N). The next N lines contain the list elements as integers. Output Format: An integer that represents the sum of only the even numbers in the list. Sample Input: 9 1 2 3 4 5 6 7 8 9 Sample Output: 20
5 ответов
+ 3
Oh, ok then
append input() to list n times
//for i in range(n) :
...
+ 2
Also, here are some tips:
Take int(input()) instead of input()
And
B=[]
for x in A:
if condition:
B.append(f(x))
Can be shortened in
B = [f(x) for x in A if condition]
+ 1
I am having trouble writting code for taking multiple inputs. The first number represents the number of inputs that follow. I have the code for the second part of the problem (getting sum of even numbers)
if int(x)% 2 == 0:
even.append(int(x))
print(sum(even)) but I don’t know how to take multiple inputs.
Any help is appreciated. Thanks
+ 1
Awesome! Thank you for the help! It worked :)
0
For each element in the list, if it's even, add to the total
Just translate in python that sentance