If you come across any unexpected problems, check the VibrantNotes Status for help. Check
Relayed
Loading Scripts...

Python Program to Check Entered Number is Neon or not.

A neon number is a type of number where the sum of the digits of its square is equal to the original number.
Python

What are Neon Numbers?

A neon number is a type of number where the sum of the digits of its square is equal to the original number. 
The correct definition is:
A positive integer n is a neon number if the sum of the digits of n2 is equal to n.

Lang : Python
num = int(input("Enter a number: "))
square = num ** 2
digit_sum = sum(int(digit) for digit in str(square))

if digit_sum == num:
    print(f"{num} is a neon number.")
else:
    print(f"{num} is not a neon number.")
Let's break down the code step by step:

1. num = int(input("Enter a number: ")): This line prompts the user to enter a number, reads the input as a string using `input()`, and then converts it to an integer using int(). The entered number is stored in the variable num.

2. square = num ** 2: This line calculates the square of the entered number (num) and assigns the result to the variable square.

3. digit_sum = sum(int(digit) for digit in str(square)): This line calculates the sum of the individual digits of the square. It converts the square to a string using str(square), then iterates over each character (digit) in the string, converting it back to an integer using int(). The sum() function then calculates the sum of these individual digits, and the result is stored in the variable `digit_sum`.

4. The if digit_sum == num: statement checks if the calculated digit sum (digit_sum) is equal to the original number (num). If the condition is true, it means that the entered number is a neon number, as the sum of the digits of its square is equal to the original number.

5. If the condition is true, it prints a message indicating that the entered number is a neon number. If the condition is false, it prints a message indicating that the entered number is not a neon number.

Copy the above code and consider checking it out on Python Interpreter:
  • If the user enters 9, the program calculates 92 = 81  , and since the sum of the digits of 81 is 9, it prints "9 is a neon number."
  • If the user enters 25, the program calculates 252 = 625, but the sum of the digits of 625 is 13, not 25, so it prints "25 is not a neon number."

Getting Info...

8 comments

  1. HI
  2. How to print pyramid pattern of multiple number?
    1. See other post you will find that code.
  3. how to print table using F strings?
  4. hlo
  5. Nice
  6. Hi
  7. Hi
We value your input but ask that you refrain from spreading hate or disclosing sensitive data. Your comment will be carefully reviewed by our admin team before it appears.
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.