4. Write an interactive program CountOddDigits that accepts an integer as its inputs and prints the number of even-valued digits in that number. An even-valued digit is either 1, 3, 5, 7, or 9. For example, the number 8546587 has four even digits (the two 5s, and a 7). So the program CountOddDigits(8546587) should return "The number of Odd Digits in 8546587 is 3".

Respuesta :

Answer:

Program :

number=int(input("Enter the number: "))#take the input from the user.

number1=number

count=0#take a variable for count.

while(number>0):#loop which check every number to be odd or not.

   value=number%10 #it is used to take the every number from integer value.

   number=int(number/10)#it is used to cut the number which is in the use.

   if(value%2!=0):#It is used to check the number to be odd.

       count=count+1#It is used to increase the value.

print("The number of Odd Digits in "+str(number1)+" is "+str(count))#It is used to print the count value of odd digit.

Output:

  • If the user inputs is '1234567890', it will prints "5".
  • If the user inputs is "8546587", it will prints "3".

Explanation:

  • The above program is in python language, which takes the integer value from the user.
  • Then The number will be distributed into many individual units with the help of a while loop.
  • The while loop runs when the number is greater than 0.
  • There is a two operation, one is used to take the number by the help of modulo operator because it gives the remainder.
  • The second operation is used to divide the number to let the number 0.
Q&A Education