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):
if x==s**3+t**3+h**3:
print("%d is a narcissistic number" %x)
  • 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):
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!")

Once, i thought l is 8128, but now i know, that’s bc he is in C. everything about him has an “i” attached to it.
I just didnt notice/face it back then.
I think i like ppl in R! Keep Real!
就像 Yibo! 喜欢,不喜欢都说出来!

  • 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):
for factor in range (2, int(sqrt(i))+1):
if i % factor ==0:
if isprime:

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!