We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents c0efd14 + 29f9e55 commit bffe705Copy full SHA for bffe705
digital_root.py
@@ -0,0 +1,47 @@
1
+"""
2
+
3
+A digital root of a number can be gitten by adding each of the individual characters until they reach a 1 digit number
4
5
+e.g
6
7
+the digital root of 45893 is
8
9
+4+5+8+9+3
10
11
+that will give us 29
12
13
+and adding up digits if 29
14
15
+2+9
16
17
+will give us 11
18
19
+adding that
20
21
+1+1
22
23
+will give us 2
24
25
26
27
+def dig_root(n):
28
29
+ '''
30
31
+ I will try to implement this without using type casting in my code
32
33
34
35
+ div , res = 10, 0
36
37
+ while n > 0:
38
39
+ res+=n%div
40
41
+ n//=div
42
43
+ return res if res<10 else dig_root(res)
44
45
+#print(dig_root(45893))
46
47
+print(dig_root (int(input())))
0 commit comments