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)
  • 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!")

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

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:

https://github.com/jackfrued/Python-100-Days/blob/master/Day01-15/05.%E6%9E%84%E9%80%A0%E7%A8%8B%E5%BA%8F%E9%80%BB%E8%BE%91.md