From 35a668f430a35c166e73c84489e85d500f458226 Mon Sep 17 00:00:00 2001 From: jatinnarula207-bot Date: Sun, 26 Oct 2025 17:25:57 +0530 Subject: [PATCH 1/2] Create digitial_root.py --- maths/digitial_root.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 maths/digitial_root.py diff --git a/maths/digitial_root.py b/maths/digitial_root.py new file mode 100644 index 000000000000..06cf8dabf4df --- /dev/null +++ b/maths/digitial_root.py @@ -0,0 +1,27 @@ +""" +digital_root.py +---------------- +Calculates the digital root of a given number. + +A digital root is obtained by summing the digits of a number repeatedly +until only a single-digit number remains. + +Example: + >>> digital_root(942) + 6 + >>> digital_root(132189) + 6 + >>> digital_root(493193) + 2 +""" + +def digital_root(n: int) -> int: + """Return the digital root of a non-negative integer.""" + while n >= 10: + n = sum(map(int, str(n))) + return n + + +if __name__ == "__main__": + num = int(input("Enter a number: ")) + print(digital_root(num)) From 5d721ab8a9a7451130625af2b7e0b84455d7dfb5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 26 Oct 2025 12:13:33 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/digitial_root.py | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/digitial_root.py b/maths/digitial_root.py index 06cf8dabf4df..c6913298c0cc 100644 --- a/maths/digitial_root.py +++ b/maths/digitial_root.py @@ -15,6 +15,7 @@ 2 """ + def digital_root(n: int) -> int: """Return the digital root of a non-negative integer.""" while n >= 10: