This function finds the number of digits in a number
def getNumOfDigits(i):
num = i
count = 1
num = num // 10
while num != 0:
count += 1
num //= 10
return count
If I try to modify the while condition to divide num by 10 and check if it is not equal to 0 it throws up a syntax error. Why is this so in python?
def getNumOfDigits(i):
num = i
count = 1
while (num //= 10)!= 0:
count += 1
return count