forked from universalDust123/Daily_coding_practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMagic_Number.py
More file actions
22 lines (19 loc) · 771 Bytes
/
Magic_Number.py
File metadata and controls
22 lines (19 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'''A magic number is that number whose repeated sum of its digits till we get a single digit is equal to 1.
Take a number as input (num).
Step 2: Calculate the sum of digits of the input number.
Repeat step 2 until we get a single digit.
If the resultant sum is equal to 1 then it is a Magic number else not.
Ex - 12345 -
Sum = 1 + 2 + 3 + 4 + 5 = 15 = 1 + 5 = 6 (Not a magic Number)
Ex - 1234
Sum = 1 + 2 + 3 + 4 = 10 = 1 + 0 = 1 (Magic Number)'''
def check_magic(number):
while len(str(number)) > 1:
sum = 0
for each in str(number):
sum += int(each)
number = sum
if number == 1:
return "Magic Number"
return "Not a Magic Number"
print(check_magic(int(input("Enter a number:"))))