Menu

Python Number Programs: Spy Number, Perfect Number & Neon Number
📰

Python Number Programs: Spy Number, Perfect Number & Neon Number

DEV Community: backend·Megalraja·about 12 hours ago
#FvLm92hm
#devtobackend#devto#dev#number#total
Long article (422 words) — no AI summary yet.
Reading 0:00
15s threshold

While learning Python, I started practising different number-based programs to improve my logical thinking and problem-solving skills.

In this blog, I'm going to explore three interesting number programs:

Spy Number

Perfect Number

Neon Number

Let's understand each one with an example and Python code using while loops.

1. Spy Number

A Spy Number is a number where the sum of its digits is equal to the product of its digits.

Example: 1124

Digits: 1, 1, 2, 4

Sum of digits:

1 + 1 + 2 + 4 = 8

Product of digits:

1 × 1 × 2 × 4 = 8

Since both results are equal, 1124 is a Spy Number.

Python Code:

num = 1124 temp = num

total = 0 product = 1

while temp > 0 : digit = temp % 10

total += digit product *= digit

temp //= 10

if total == product : print ( "Spy Number" ) else : print ( "Not a Spy Number" )

Enter fullscreen mode

Exit fullscreen mode

Output:

Spy Number

Enter fullscreen mode

Exit fullscreen mode

2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.