{"id":15118,"date":"2021-09-30T17:00:36","date_gmt":"2021-09-30T11:30:36","guid":{"rendered":"https:\/\/python-programs.com\/?p=15118"},"modified":"2021-11-22T18:33:34","modified_gmt":"2021-11-22T13:03:34","slug":"python-program-for-neon-number","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-neon-number\/","title":{"rendered":"Python Program for Neon Number"},"content":{"rendered":"
Are you new to the java programming language? We recommend you to ace up your practice session with these Basic Java Programs Examples<\/a><\/p>\n Given a number, the task is to check whether the given number is a Neon Number or not in Python.<\/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 check whether the given number is a Neon Number or Not.<\/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 Are you new to the java programming language? We recommend you to ace up your practice session with these Basic Java Programs Examples Given a number, the task is to check whether the given number is a Neon Number or not in Python. Neon Number: A Neon Number is a number whose square sum of …<\/p>\nGiven Number = 9<\/pre>\n
The Given Number [ 9 ] is a neon Number<\/pre>\n
Given Number =123<\/pre>\n
The Given Number [ 123 ] is not a neon Number<\/pre>\n
Program for Neon Number in Python<\/h2>\n
\n
Method #1: Using list() and sum() functions (Static Input)<\/h3>\n
\n
#Give the number as static input and store it in a variable.\r\ngivnumb=9\r\n#Calculate the square of the given number using the ** operator \r\n#or multiply the given number by itself and store it in a variable.\r\nsquarnumb=givnumb**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\nnumbedigit=list(map(int,str(givnumb)))\r\n#Calculate the sum of digits of this list using the sum() function.\r\nsumdigi=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.\r\nif(sumdigi==givnumb):\r\n print('The Given Number [',givnumb,'] is a neon Number')\r\n#Else the given number is not a Neon Number.\r\nelse:\r\n print('The Given Number [',givnumb,'] is not a neon Number')\r\n<\/pre>\n
The Given Number [ 9 ] is a neon Number<\/pre>\n
Method #2: Using list() and sum() functions (User Input)<\/h3>\n
\n
# Give the number as user input using int(input()) function and store it in a variable\r\ngivnumb = int(input('Enter some random number ='))\r\n# Calculate the square of the given number using the ** operator\r\n# or multiply the given number by itself and store it in a variable.\r\nsquarnumb = givnumb**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\nnumbedigit = list(map(int, str(givnumb)))\r\n# Calculate the sum of digits of this list using the sum() function.\r\nsumdigi = 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.\r\nif(sumdigi == givnumb):\r\n print('The Given Number [', givnumb, '] is a neon Number')\r\n# Else the given number is not a Neon Number.\r\nelse:\r\n print('The Given Number [', givnumb, '] is not a neon Number')\r\n<\/pre>\n
Enter some random number =123\r\nThe Given Number [ 123 ] is not a neon Number<\/pre>\n
\n