+ 1
Why does this code fail the third test case od That's odd... In python 3?
a =int(input()) n = [] counter = 0 sum = 0 while a > counter: b = (input()) n.append(b) counter += len(b) for x in n: if int(x) % 2 == 0: sum += int(x) print(sum)
3 ответов
+ 3
Thiago Silva ,
# there is only 1 line to rework and get your code run (<<<)
a =int(input())
n = []
counter = 0
sum_ = 0 # don't use 'sum' as a variable name, since there is a built-in function with the same name
while a > counter:
b = input()
n.append(b)
#counter += len(b) # see next line
counter += 1 # <<<
for x in n:
if int(x) % 2 == 0:
sum_ += int(x)
print(sum_)
+ 1
Thank you!
0
n = int(input())
s = 0
for i in range(0, n):
x = int(input())
if x % 2 == 0: s += x
print(s)
Sample Input:
9
1
2
3
4
5
6
7
8
9