Anyone know how to find all the even digits of a number?

Hello, anyone can help me to find all even digits of a number and then return the number of even digits. i tried this , but it didn’t work:

number = int(input())
number_1 = str(number)
a= number_1.split("delimiter")
b = len(a)
count = 0
for i in a:
	if i% 2 == 0:
		count+=1

print(count)

Thanks

Sure, try this:

number = 200

for char in str(number):
  if int(char) % 2 == 0:
    print("even")
  else:
    print("odd")

Your issue is that you are converted the number to a string and then looping through it but not converting each character back into an int to check if it’s even.

3 Likes

You also don’t need to split a string to loop through it. Strings are literally just an array/list of chars

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.