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)
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
+ 2
lenth = int(input())
a = 0
total = 0
while a<lenth:
i = int(input())
if i%2==0:
total+=i
a+=1
print(total)