Python program to check and print the neon number upto 1000 using function.
Answers
Answered by
3
Answer:
# Python program to check and print
# Neon Numbers upto 10000
# function to check Neon Number
def checkNeon (x) :
# storing the square of x
sq = x * x
# calculating the sum of sum of digits
# of sqr
sum_digits = 0
while (sq != 0) :
sum_digits = sum_digits + sq % 10
sq = sq / 10
return (sum_digits == x)
# Driver Code
i = 1
# Printing Neon Numbers upto 10000
while i <= 10000 :
if (checkNeon(i)) :
print i,
i = i + 1
Answered by
2
Program
temp = 0
pro = 0
for i in range(0,10001,1):
temp = i * i
while temp > 0:
pro = pro + (temp % 10)
temp = int(temp / 10)
if i == pro:
print(i)
pro = 0
i = i +1
Output
0
1
9
Explanation
- First i initialized a for loop upto 10000 number
- then i took the value of i for each iteration
- and multiplied it by itself
- and calculated the sum of digits in the multiplied number
- and i wrote an if condition to check whether the sum i got is equal to the number i took in for loop
- if true i wrote a print statement to print that number
- else it will loop until the condition false at 10001
---Hope this Helps :)
Similar questions