用Python来判断过剩数的方法示例,python过剩数示例,在用Python来判断过


在用Python来判断过剩数的方法示例之前,要知道什么是过剩数。说到过剩数,应该是有很多人不理解它的概念。我更喜欢叫它为Abundant Number,它是一种特殊的自然数,它的特点是除去它本身以外的一切正约数的和大于它本身。

用Python来判断过剩数的方法示例,源码如下:

#Checks if a number is abundant or not#An abundant number is the number of which sum of factors(including itself) is greater than twice the number#www.iplaypy.comdef abundant(n):    sum_factors=0    for i in range(1,n+1):        if n%i==0:      #finds out the factors            f=i            sum_factors += f                if sum_factors>2*n:                #condition for abundant number        print "This is an Abundant Number!"    else:        print "This is not an Abundant Number!"

编橙之家文章,

评论关闭