{"id":16257,"date":"2021-08-12T09:36:41","date_gmt":"2021-08-12T04:06:41","guid":{"rendered":"https:\/\/python-programs.com\/?p=16257"},"modified":"2021-11-22T18:38:27","modified_gmt":"2021-11-22T13:08:27","slug":"python-program-to-print-all-disarium-numbers-within-given-range","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-all-disarium-numbers-within-given-range\/","title":{"rendered":"Python Program to Print all Disarium Numbers within Given range"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Get Tangent value Using math.tan()<\/a> A Disarium number is one in which the sum of each digit raised to the power of its respective position equals the original number.<\/p>\n like 135 , 89, etc.<\/p>\n Here 1^1 + 3^2 + 5^3 = 135 so it is disarium Number<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example 2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to Print all Disarium Numbers within the given range.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Get Tangent value Using math.tan() Disarium Number: A Disarium number is one in which the sum of each digit raised to the power of its respective position equals the original number. like 135 , 89, etc. Here 1^1 + 3^2 + 5^3 = 135 so …<\/p>\n
\nDisarium Number:<\/strong><\/p>\nGiven lower limit range = 7\r\nGiven upper limit range = 180<\/pre>\n
The disarium numbers in the given range 7 and 180 are: \r\n7 8 9 89 135 175<\/pre>\n
Given lower limit range = 1\r\nGiven upper limit range = 250<\/pre>\n
The disarium numbers in the given range 1 and 250 are:\r\n1 2 3 4 5 6 7 8 9 89 135 175<\/pre>\n
Program to Print all Disarium Numbers within Given range<\/h2>\n
\n
Method #1: Using For Loop (Static input)<\/h3>\n
\n
# Give the lower limit range as static input and store it in a variable.\r\nlowlim_range = 7\r\n# Give the upper limit range as static input and store it in another variable.\r\nupplim_range = 180\r\nprint('The disarium numbers in the given range',\r\n lowlim_range, 'and', upplim_range, 'are:')\r\n# Loop from lower limit range to upper limit range using For loop.\r\nfor m in range(lowlim_range, upplim_range+1):\r\n\r\n # given number\r\n num = m\r\n # intialize result to zero(ans)\r\n ans = 0\r\n\r\n # calculating the digits\r\n digit_s = len(str(num))\r\n # copy the number in another variable(duplicate)\r\n dup_numbr = num\r\n while (dup_numbr != 0):\r\n # getting the last digit\r\n remaindr = dup_numbr % 10\r\n # multiply the result by a digit raised to the power of the iterator value.\r\n ans = ans + remaindr**digit_s\r\n digit_s = digit_s - 1\r\n dup_numbr = dup_numbr\/\/10\r\n # It is disarium number if it is equal to original number\r\n if(num == ans):\r\n print(num, end=' ')\r\n<\/pre>\n
The disarium numbers in the given range 7 and 180 are:\r\n7 8 9 89 135 175<\/pre>\n
Method #2: Using For Loop (User input)<\/h3>\n
\n
# Give the lower limit range as user input using the int(input()) function and store it in a variable.\r\nlowlim_range = int(input(\"Enter some Random number = \"))\r\n# Give the upper limit range as user input using the int(input()) function and store it in another variable.\r\nupplim_range = int(input(\"Enter some Random number = \"))\r\nprint('The disarium numbers in the given range',\r\n lowlim_range, 'and', upplim_range, 'are:')\r\n# Loop from lower limit range to upper limit range using For loop.\r\nfor m in range(lowlim_range, upplim_range+1):\r\n\r\n # given number\r\n num = m\r\n # intialize result to zero(ans)\r\n ans = 0\r\n\r\n # calculating the digits\r\n digit_s = len(str(num))\r\n # copy the number in another variable(duplicate)\r\n dup_numbr = num\r\n while (dup_numbr != 0):\r\n # getting the last digit\r\n remaindr = dup_numbr % 10\r\n # multiply the result by a digit raised to the power of the iterator value.\r\n ans = ans + remaindr**digit_s\r\n digit_s = digit_s - 1\r\n dup_numbr = dup_numbr\/\/10\r\n # It is disarium number if it is equal to original number\r\n if(num == ans):\r\n print(num, end=' ')\r\n<\/pre>\n
Enter some Random number = 1\r\nEnter some Random number = 250\r\nThe disarium numbers in the given range 1 and 250 are:\r\n1 2 3 4 5 6 7 8 9 89 135 175<\/pre>\n
\n