Write your code: Number of Digits#

Write a function that returns the number of digits for a given integer number.

Rules#

  1. Input: integer (int) number (+ or -)

  2. Solve this challenge without using strings or any external package.

  3. The function must return a integer value corresponding to the number of digits of the input number.

Function definition#

def get_digits(n):
    #write your function here
  File "/tmp/ipykernel_2041/2947767192.py", line 2
    #write your function here
                             ^
SyntaxError: unexpected EOF while parsing

Testing#

Check if your function returns the expected value using the cell below.

import unittest

class UnitTests(unittest.TestCase):
    def test_type(self):
        self.assertTrue(isinstance(get_digits(13124), int), 'The function should return an integer.')
    def test1(self):
        self.assertEqual(get_digits(13124), 5)
    def test2(self):
        self.assertEqual(get_digits(0), 1)
    def test3(self):
        self.assertEqual(get_digits(-12381428), 8)
    def test4(self):
        self.assertEqual(get_digits(12), 2)
    def test5(self):
        self.assertEqual(get_digits(42), 2)
    def test6(self):
        self.assertEqual(get_digits(1000), 4)
    def test7(self):
        self.assertEqual(get_digits(136), 3)
    def test8(self):
        self.assertEqual(get_digits(1000000000), 10)
    def test9(self):
        self.assertEqual(get_digits(2147483647), 10)
unittest.main(argv=[''], verbosity=2,exit=False)