diff --git a/digital_image_processing/resize/resize.py b/digital_image_processing/resize/resize.py index b7d493e70b4b..4fd222ccd6c6 100644 --- a/digital_image_processing/resize/resize.py +++ b/digital_image_processing/resize/resize.py @@ -11,7 +11,7 @@ class NearestNeighbour: def __init__(self, img, dst_width: int, dst_height: int): if dst_width < 0 or dst_height < 0: - raise ValueError(f"Destination width/height should be > 0") + raise ValueError("Destination width/height should be > 0") self.img = img self.src_w = img.shape[1] diff --git a/maths/number_of_digits.py b/maths/number_of_digits.py new file mode 100644 index 000000000000..12717065149e --- /dev/null +++ b/maths/number_of_digits.py @@ -0,0 +1,18 @@ +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