number of digits Algorithm

P or p is the 16th letter of the modern English alphabet and the ISO basic Latin alphabet. Its name in English is pee (pronounced), plural pees. The Semitic Pê (mouth), as well as the Greek Π or π (pi), and the Etruscan and Latin letters that developed from the former alphabet, all symbolized /p/, a voiceless bilabial plosive.
def num_digits(n: int) -> int:
    """
    Find the number of digits in a number.

    >>> num_digits(12345)
    5
    >>> num_digits(123)
    3
    """
    digits = 0
    while n > 0:
        n = n // 10
        digits += 1
    return digits


if __name__ == "__main__":
    print(num_digits(12345))  # ===> 5

LANGUAGE:

DARK MODE: