Dremendo Tag Line

Input a number and check whether all digits are even or not using while loop in Python

while Loop - Question 12

In this question, we will see how to input a number and check if all digits in the number are even digit or not in Python programming using while loop. To know more about while loop click on the while loop lesson.

Q12) Write a program in Python to input a number and check if all digits in the number are even digit or not using while loop.

Program

td=0; ed=0
n=int(input('Enter any number '))

while n>0:
    d=n%10
    if d%2==0:
        ed=ed+1     # counting the even digits

    td=td+1         # counting the total number of digits
    n=n//10

if td==ed:
    print('All digits are even digit')
else:
    print('All digits are not even digit')

Output

Enter any number 6248
All digits are even digit
video-poster