Why does this code fail the third test case od That's odd... In python 3? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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)

30th Apr 2022, 11:52 PM
Thiago Silva
Thiago Silva - avatar
3 Answers
+ 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_)
1st May 2022, 9:50 AM
Lothar
Lothar - avatar
+ 1
Thank you!
1st May 2022, 10:43 AM
Thiago Silva
Thiago Silva - avatar
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
1st May 2022, 1:24 AM
SoloProg
SoloProg - avatar