We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e2a78d4 commit 35a668fCopy full SHA for 35a668f
maths/digitial_root.py
@@ -0,0 +1,27 @@
1
+"""
2
+digital_root.py
3
+----------------
4
+Calculates the digital root of a given number.
5
+
6
+A digital root is obtained by summing the digits of a number repeatedly
7
+until only a single-digit number remains.
8
9
+Example:
10
+ >>> digital_root(942)
11
+ 6
12
+ >>> digital_root(132189)
13
14
+ >>> digital_root(493193)
15
+ 2
16
17
18
+def digital_root(n: int) -> int:
19
+ """Return the digital root of a non-negative integer."""
20
+ while n >= 10:
21
+ n = sum(map(int, str(n)))
22
+ return n
23
24
25
+if __name__ == "__main__":
26
+ num = int(input("Enter a number: "))
27
+ print(digital_root(num))
0 commit comments