{"id":15308,"date":"2021-10-01T10:30:38","date_gmt":"2021-10-01T05:00:38","guid":{"rendered":"https:\/\/python-programs.com\/?p=15308"},"modified":"2021-11-22T18:33:28","modified_gmt":"2021-11-22T13:03:28","slug":"python-program-to-print-neon-numbers-in-a-range","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-neon-numbers-in-a-range\/","title":{"rendered":"Python Program to Print Neon numbers in a Range"},"content":{"rendered":"
In this article, we will learn how to print Neon numbers within a specific range in Python. You will learn what a Neon number is, how to check whether a given number is a Neon number, and how to write a Python code that outputs all the Neon numbers within the user-specified range.<\/p>\n
Neon Number:<\/strong><\/p>\n A Neon Number is a number whose square sum of digits equals the original number.<\/p>\n Ex: 9<\/p>\n Square of 9 =81<\/p>\n Sum of digits of square = 8 +1 =9 ,So it is Neon Number<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to print all the Neon numbers in the given range.<\/p>\n Don’t miss the chance of Java programs examples with output pdf free download<\/a> as it is very essential for all beginners to experienced programmers for cracking the interviews.<\/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 Related Programs<\/strong>:<\/p>\n In this article, we will learn how to print Neon numbers within a specific range in Python. You will learn what a Neon number is, how to check whether a given number is a Neon number, and how to write a Python code that outputs all the Neon numbers within the user-specified range. Neon Number: …<\/p>\nGiven upper limit range =1\r\nGiven lower limit range =7<\/pre>\n
The Neon numbers in the given range 1 and 7 are:\r\n1<\/pre>\n
Given upper limit range =1\r\nGiven lower limit range =23<\/pre>\n
Enter lower limit range and upper limit range separate bt spaces = 1 23\r\nThe Neon numbers in the given range 1 and 23 are:\r\n1 9<\/pre>\n
Program to Print Neon numbers in a Range in Python<\/h2>\n
\n
Method #1: Using list() and sum() functions (Static Input)<\/h3>\n
\n
# Create a function checkNeonNumb() which accepts the number as an argument and\r\n# returns true if it is Neon number else returns False.\r\n\r\n\r\ndef checkNeonNumb(numb):\r\n # Calculate the square of the given number\/argument using the ** operator or multiply\r\n # the given number by itself and store it in a variable.\r\n squarnumb = numb**2\r\n # Convert this squared number into a list of digits\r\n # using list(),int(),map(),str() functions.\r\n # Store this list in a variable.\r\n numbedigit = list(map(int, str(squarnumb)))\r\n # Calculate the sum of digits of this list using the sum() function.\r\n sumdigi = sum(numbedigit)\r\n # Check if this sum is equal to the given number\r\n # or not using the If conditional statement.\r\n # If it is true then the given number is a Neon Number so return True\r\n if(sumdigi == numb):\r\n return True\r\n # Else the given number is not a Neon Number so return False.\r\n else:\r\n return False\r\n\r\n\r\n# Give the lower limit range as static input and store it in a variable.\r\nlowlimrange = 1\r\n# Give the upper limit range as static input and store it in another variable.\r\nupplimrange = 7\r\nprint('The Neon numbers in the given range',\r\n lowlimrange, 'and', upplimrange, 'are:')\r\n# Loop from lower limit range to upper limit range using For loop.\r\nfor p in range(lowlimrange, upplimrange+1):\r\n # Inside the for loop pass the iterator value to checkNeonnumb() function.\r\n if(checkNeonNumb(p)):\r\n # If it returns true then print the iterator value.\r\n print(p, end=' ')\r\n<\/pre>\n
The Neon numbers in the given range 1 and 7 are:\r\n1<\/pre>\n
Method #2: Using list() and sum() functions (User Input)<\/h3>\n
\n
# Create a function checkNeonNumb() which accepts the number as an argument and\r\n# returns true if it is Neon number else returns False.\r\n\r\n\r\ndef checkNeonNumb(numb):\r\n # Calculate the square of the given number\/argument using the ** operator or multiply\r\n # the given number by itself and store it in a variable.\r\n squarnumb = numb**2\r\n # Convert this squared number into a list of digits\r\n # using list(),int(),map(),str() functions.\r\n # Store this list in a variable.\r\n numbedigit = list(map(int, str(squarnumb)))\r\n # Calculate the sum of digits of this list using the sum() function.\r\n sumdigi = sum(numbedigit)\r\n # Check if this sum is equal to the given number\r\n # or not using the If conditional statement.\r\n # If it is true then the given number is a Neon Number so return True\r\n if(sumdigi == numb):\r\n return True\r\n # Else the given number is not a Neon Number so return False.\r\n else:\r\n return False\r\n\r\n\r\n# Give the lower limit range and upper limit range as\r\n# user input using map(),int(),split() functions.\r\n# Store them in two separate variables.\r\nlowlimrange, upplimrange = map(int, input(\r\n 'Enter lower limit range and upper limit range separate bt spaces = ').split())\r\nprint('The Neon numbers in the given range',\r\n lowlimrange, 'and', upplimrange, 'are:')\r\n# Loop from lower limit range to upper limit range using For loop.\r\nfor p in range(lowlimrange, upplimrange+1):\r\n # Inside the for loop pass the iterator value to checkNeonnumb() function.\r\n if(checkNeonNumb(p)):\r\n # If it returns true then print the iterator value.\r\n print(p, end=' ')\r\n<\/pre>\n
Enter lower limit range and upper limit range separate bt spaces = 1 23\r\nThe Neon numbers in the given range 1 and 23 are:\r\n1 9<\/pre>\n
\n