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)

3rd Sep 2021, 9:25 AM
Ermias Kebede
Ermias Kebede - avatar
4 ответов
+ 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.
3rd Sep 2021, 9:29 AM
Vadivelan
+ 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
3rd Sep 2021, 9:53 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Ric Wittlop I appreciate your timely and simple solution but I have already solved it with earlier solution by vadivelan
3rd Sep 2021, 9:57 AM
Ermias Kebede
Ermias Kebede - avatar
+ 1
Well done buddy!
3rd Sep 2021, 9:59 AM
Rik Wittkopp
Rik Wittkopp - avatar