Followers

Showing posts with label Neon Number. Show all posts
Showing posts with label Neon Number. Show all posts

Wednesday, April 26, 2023

A Python program to check if a given number is a neon number or not.

 

A neon number is a number where the sum of digits of the square of the number is equal to the number itself. In other words, if we take a number, square it, add up the digits of the result, and the sum is equal to the original number, then that number is called a neon number.

For example, 9 is a neon number because:

9^2 = 81 8 + 1 = 9

Another example is 1, as:

1^2 = 1 1 = 1

So, 1 is also a neon number.

Here's a Python program to check if a given number is a neon number or not:

python
number = int(input("Enter a number: ")) square = number * number sum_of_digits = 0 # calculate sum of digits of the square of the number while square > 0: digit = square % 10 sum_of_digits += digit square //= 10 # check if the sum of digits is equal to the original number if sum_of_digits == number: print(number, "is a neon number") else: print(number, "is not a neon number")

In this program, I first take the input number from the user. I then calculate the square of the number and store it in the variable square. I then calculate the sum of digits of the square of the number using a while loop. Inside the while loop, I extract the last digit of the square using the modulus operator and add it to the sum_of_digits variable. I then remove the last digit from square using integer division by 10. I repeat this process until square becomes 0.

After calculating the sum of digits of the square of the number, I check if it is equal to the original number. If it is, I print a message saying that the number is a neon number. Otherwise, I print a message saying that the number is not a neon number.