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 digits equals the original number.
Ex: 9
Square of 9 =81
Sum of digits of square = 8 +1 =9 ,So it is Neon Number
Examples:
Example1:
Input:
Given Number = 9
Output:
The Given Number [ 9 ] is a neon Number
Example2:
Input:
Given Number =123
Output:
The Given Number [ 123 ] is not a neon Number
Program for Neon Number in Python
Below are the ways to check whether the given number is a Neon Number or Not.
Method #1: Using list() and sum() functions (Static Input)
Approach:
- Give the number as static input and store it in a variable.
- Calculate the square of the given number using the ** operator or multiply the given number by itself and store it in a variable.
- Convert this squared number into a list of digits using list(),int(),map(),str() functions.
- Store this list in a variable.
- Calculate the sum of digits of this list using the sum() function.
- Check if this sum is equal to the given number or not using the If conditional statement.
- If it is true then the given number is a Neon Number.
- Else the given number is not a Neon Number.
- The Exit of the Program.
Below is the implementation:
#Give the number as static input and store it in a variable.
givnumb=9
#Calculate the square of the given number using the ** operator
#or multiply the given number by itself and store it in a variable.
squarnumb=givnumb**2
#Convert this squared number into a list of digits
#using list(),int(),map(),str() functions.
#Store this list in a variable.
numbedigit=list(map(int,str(givnumb)))
#Calculate the sum of digits of this list using the sum() function.
sumdigi=sum(numbedigit)
#Check if this sum is equal to the given number
#or not using the If conditional statement.
#If it is true then the given number is a Neon Number.
if(sumdigi==givnumb):
print('The Given Number [',givnumb,'] is a neon Number')
#Else the given number is not a Neon Number.
else:
print('The Given Number [',givnumb,'] is not a neon Number')
Output:
The Given Number [ 9 ] is a neon Number
Method #2: Using list() and sum() functions (User Input)
Approach:
- Give the number as user input using the int(input()) function and store it in a variable.
- Calculate the square of the given number using the ** operator or multiply the given number by itself and store it in a variable.
- Convert this squared number into a list of digits using list(),int(),map(),str() functions.
- Store this list in a variable.
- Calculate the sum of digits of this list using the sum() function.
- Check if this sum is equal to the given number or not using the If conditional statement.
- If it is true then the given number is a Neon Number.
- Else the given number is not a Neon Number.
- The Exit of the Program.
Below is the implementation:
# Give the number as user input using int(input()) function and store it in a variable
givnumb = int(input('Enter some random number ='))
# Calculate the square of the given number using the ** operator
# or multiply the given number by itself and store it in a variable.
squarnumb = givnumb**2
# Convert this squared number into a list of digits
# using list(),int(),map(),str() functions.
# Store this list in a variable.
numbedigit = list(map(int, str(givnumb)))
# Calculate the sum of digits of this list using the sum() function.
sumdigi = sum(numbedigit)
# Check if this sum is equal to the given number
# or not using the If conditional statement.
# If it is true then the given number is a Neon Number.
if(sumdigi == givnumb):
print('The Given Number [', givnumb, '] is a neon Number')
# Else the given number is not a Neon Number.
else:
print('The Given Number [', givnumb, '] is not a neon Number')
Output:
Enter some random number =123 The Given Number [ 123 ] is not a neon Number
Related Programs:
- python count number of true elements in numpy array in python
- convert the base of a number to any other base in number system
- python program to find the factorial of a number
- harshad number in python
- disarium number in python
- python program to check armstrong number
- python program to compute the power of a number
