python day 22

Today we will introduce two kinds of interesting number: **Narcissistic** Number, **Perfect** Number, and **Prime** Number.

**Narcissistic Number**

##### numbers that can be represented as the sum of the cube of each digits.

def nar(): for x in range (1,1001): s=x%10 t=x//10%10 h=x//100 if x==s**3+t**3+h**3: print("%d is a narcissistic number" %x)

```
nar()
1 is a narcissistic number
153 is a narcissistic number
370 is a narcissistic number
371 is a narcissistic number
407 is a narcissistic number
1000 is a narcissistic number
```

**Perfect Number**

the number is equal to its sum of proper divisors.

from math import sqrt def perfect(m): for i in range (1,m): s=0 for factor in range (1, int(sqrt(i))+1): if i % factor==0: s +=factor if factor >1 and i//factor != factor: s+= i//factor if s==i: print(i,"is a perfect number" ) print("So you are perfect2!")

```
perfect(10000)
```

**Prime**Number

The only divisor of the number is 1 and itself

from math import sqrt def prime(m): for i in range (2,m): isprime=True for factor in range (2, int(sqrt(i))+1): if i % factor ==0: isprime=False break if isprime: print(i)

`prime(100)`

Story time:

Narcissistic flower is daffodil, a handsome boy fell in love with the beauty of himself when he saw himself in the lake.

he became a daffodil so he can look at himself all day long!

Happy studying!

Ref: