human
Check if a number is magic ( Recursive sum of digits is 1 ) | Python3 program to check if a number is Magic number ..
Note that the loop continues if n is 0 and sum is non - zero . It stops when n becomes 0 and sum becomes single digit ..
Return true if sum becomes 1..
Driver code"
How can the above be solved in Python?
assistant
#Here is code to check if a number is magic ( Recursive sum of digits is 1 ) and the other steps required.
 def isMagic ( n ) :
	sum = 0 ;
	while ( n > 0 or sum > 9 ) :
		if ( n == 0 ) :
			n = sum ;
			sum = 0 ;
		sum = sum + n % 10 ;
		n = int ( n / 10 ) ;
	return True if ( sum == 1 ) else False ;
n = 1234 ;
if ( isMagic ( n ) ) :
	print ( " Magic ▁ Number " ) ;
else :
	print ( " Not ▁ a ▁ magic ▁ Number " ) ;