The code checks if a given number is a “neon number” or not.
A neon number is a number that is equal to the sum of the digits of the square of the number.
Here’s the explanation of how the code works:
num
.num
is calculated and stored in the variable square
.square
is not equal to 0.square
is extracted and stored in the variable digit
.sum
.square
is updated by floor division of square
by 10. This will remove the last digit of the square
.num
is equal to sum
.num
is equal to sum
, then the code prints num
is a neon number. If num
is not equal to sum
, then the code prints num
is not a neon number.sum = 0
print("Enter the number to check:")
num = int(input())
square = num * num
while (square != 0):
digit = square % 10
sum = sum + digit
square = square // 10
if (num == sum):
print(str(num) + " is a neon number.")
else:
print(str(num) + " is not a neon number.")
Enter a number to check for neon number:
9
9 is a neon number.
Enter a number to check for neon number:
30
30 is not a neon number.