I changed 2 things :
- while n > 1:instead of- while n > 0:otherwise your loop never stops
- n=n//10instead of- n=n/10, where- //is the euclidian division, which is what you need here
You should try this :
def testD(D,n):
    if D % 2 == 0:
        return 0
    count = 0
    while n > 1:
        if(n%10) %2==1:
            count +=1
        n=n//10
    return count
print(testD(7, 555))
# output : 3 (because 7 is odd, and there is 3 odd digits in 555)
2
solved programing function in python