Выскакивает ошибка: TypeError: 'int' object is not iterable

Нужно вывести сумму всех четных чисел:

numbers = (9,1,2,3,4,5,6,7,8,9)
i = 0
for x in numbers:
  if x % 2 == 0:
    while int(x) > i:
      i += 2
      print(sum(i))

На print(sum(i)) Выскакивает ошибка: TypeError: 'int' object is not iterable


Ответы (1 шт):

Автор решения: n1tr0xs
numbers = [9,1,2,3,4,5,6,7,8,9]
s = 0
for num in numbers:
  if not x % 2:
      s += 2
print(s)

Либо так можно

numbers = [9,1,2,3,4,5,6,7,8,9]
s = sum(x for x in numbers if not x%2)
→ Ссылка