Python neon number

Neon number is number,in which sum of digits of square of number, is same as number itself

For example 9 is neon number 

  1. square  of 9 is 81.
  2. Sum of digits of square i.e. 81 is 9.
  3. Sum of digits (9) and number(9) is matching. 

 

neon.py

iSquare=0
iDigit=0
iSum=0

//Input number and convert to numeric form

iNumber=int(input(“Please enter a number: “))

//Square the input number

iSquare=iNumber**2

//Calculate sum of digits of square

while iSquare>0:
iDigit=iSquare%10
iSum=iSum+iDigit
iSquare=iSquare//10

//Compare sum of digits and input number

if iSum==iNumber:
print(iNumber,” is neon number”)
else:
print(iNumber,” is not neon number”)

Output

neon

 

Published by Python programming examples for beginners

Abhay Gadkari is an IT professional having around experience of 20+ years in IT industry. He worked on web technologies and databases with Insurance and ERP projects.