A magic number is that number whose repeated sum of its digits till we get a single digit is equal to 1.

Magic number in python

Steps to Check Magic Number in Python

  1. Take a number as input (num).
  2. Calculate the sum of digits of the input number.
  3. Repeat step 2 until we get a single digit.
  4. If resultant sum is equal to 1 then it is a Magic number else not.

We will calculate the sum of the digits until we get a single-digit number as the sum. To count the number of digits we will use math.log10()+1.

Check Whether a number is a Magic Number in Python


Find all the Magic Numbers in the interval in Python

Any doubts then comment below.

This Post Has 2 Comments

  1. venkat

    please make it that after adding the digits in the number given the answer should be 1

    1. admin

      Thanks for the suggestion.

Leave a Reply

three × four =