Python Program to Check a Number is a Neon Number

Write a Python program to check a number is a neon number or not using a while loop. If a number equals the sum of square number digits, it is a neon number. For instance, 9 is because 92 = 81 and 8 +1 = 9

In this python example, first, we find the square of a number. Next, divide that square into individual digits and find the sum. If the sum equals the actual number, it is a neon number.

import math

Number = int(input("Enter the Number to Check Neon Number = "))
Sum = 0

squr = math.pow(Number, 2)
print("Square of a Given Digit = %d" %squr)

while squr > 0:
    rem = squr % 10
    Sum = Sum + rem
    squr = squr // 10

print("The Sum of the Digits   = %d" %Sum)

if Sum == Number:
    print("\n%d is a Neon Number." %Number)
else:
    print("%d is Not a Neon Number." %Number)
Python Program to Check a Number is a Neon Number

Python program to check a number is a neon number or not using recursion or recursive functions.

# Python Program to Check Neon Number
import math
Sum = 0

def neonNumber(squr):
    global Sum
    if squr > 0:
        rem = squr % 10
        Sum = Sum + rem
        neonNumber(squr // 10)
    return Sum

    
Number = int(input("Enter the Number to Check Neon Number = "))

squr = math.pow(Number, 2)
print("Square of a Given Digit = %d" %squr)

Sum = neonNumber(squr)
print("The Sum of the Digits   = %d" %Sum)

if Sum == Number:
    print("\n%d is a Neon Number." %Number)
else:
    print("%d is Not a Neon Number." %Number)
Enter the Number to Check Neon Number = 44
Square of a Given Digit = 1936
The Sum of the Digits   = 19
44 is Not a Neon Number.

Enter the Number to Check Neon Number = 9
Square of a Given Digit = 81
The Sum of the Digits   = 9

9 is a Neon Number.

Python program to print neon numbers from 1 to n using for loop and while loop.

import math

MinNeon = int(input("Please Enter the Minimum = "))
MaxNeon = int(input("Please Enter the Maximum = "))

for i in range(MinNeon, MaxNeon + 1):
    Sum = 0
    squr = math.pow(i, 2)

    while squr > 0:
        rem = squr % 10
        Sum = Sum + rem
        squr = squr // 10

    if Sum == i:
        print(i, end = '  ')
Please Enter the Minimum = 1
Please Enter the Maximum = 10000
1  9