Python program to Get Number of Even and Odd Digits

x = int(input("Insert some numbers: "))
ev = 0
od = 0
while x > 0:
 if x%2 ==0:
  ev += 1
 else:
  od += 1
 x = x//10
print("Even numbers = %d, Odd numbers = %d" % (ev,od))

 

 

Output:

Insert some numbers: 12457
Even numbers = 2, Odd numbers = 3

 

Insert some numbers: 1982364
Even numbers = 4, Odd numbers = 3

Subscribe For Daily Updates