0
Need quick fix to this code below !!!
numlist = [ ] evensum = 0 number = int(input()) for i in range(1, number +1): value = int(input()) numlist.append(value) for j in range(number): if( numlist[j] % 2 == 0 ): evensum = evensum + numlist[j] print(evensum)
4 Answers
+ 2
Set indentation for numlist.append(value) same as previous line.
for i in range(1, number +1):
value = int(input())
numlist.append(value)
I fixed only error, not solve the problem.
+ 2
Ermias Bibi
You have been given an excellent answer by Vadivelan , but I would like you to consider the following alternate code:
evensum = 0
number = int(input())
for i in range(number):
value = int(input())
if value %2 ==0:
evensum += value
print(evensum)
This option assesses the input number to be odd/even & increments evensum if number is even.
This stops a lot of iteration which takes time, and gives a more direct solution.
PS: Good code you put together
+ 1
Ric Wittlop I appreciate your timely and simple solution but I have already solved it with earlier solution by vadivelan
+ 1
Well done buddy!