Find Magic Number - Python
Hi Friends, Here I solved magic number problem by python A number is said to be a magic number, if the sum of its digits are calculated till a single digit recursively by adding the sum of the digits after every addition. If the single digit comes out to be 1,then the number is a magic number CODE: def magic(n): a = len(str(n)) sum = 0 for i in str(n): sum += int(i) if len(str(sum)) == 1: return sum else: return magic(sum) a = int(input("Enter a range to find: ")) c = [] for i in range(1,a+1): result = magic(i) if result == 1: c.append(i) print(c) ------------- By PyKAR