Search code examples
python-3.xtypeerrordigits

Find the sum of an even number from a list of integers


input-258345
    output-14
    ex-2+8+4=14
myList = input()
result = 0
for i in myList:
  if not i % 2:
    result += i

print(result)

I am getting an error:

if not i % 2:
TypeError: not all arguments converted during string formatting

Solution

  • mylist = list(input())
    result = 0
    for i in mylist:
      if int(i) % 2 ==0:
        result += int(i)
    print(result)