0

Cant accept above 10,help please

#Adding all even numbers challenge... #Has no value error a= list(input("Enter numbers;")) sum=0 print("Your numbers are "+ str(a)) print("ADDING ALL EVEN NUMBERS...") for i in a: try: if (int(i))%2==0: print("Even.." + str(i)) sum+=int(i) else: print("Odd..." + str(i)) print("Skipping...") continue except ValueError: print("Unknown value!!") continue print(sum)

8th Jun 2020, 1:48 PM
Davie Planter
Davie Planter - avatar
2 Réponses
+ 2
Why dont you just filter all numbers that are not even from a list then use the sum() function to add the remaining elements in a list
8th Jun 2020, 4:07 PM
boolean
boolean - avatar
+ 2
lenth = int(input()) a = 0 total = 0 while a<lenth: i = int(input()) if i%2==0: total+=i a+=1 print(total)
10th Jun 2020, 9:03 PM
Taran Grover
Taran Grover - avatar