Python判断Abundant Number的方法

yipeiwu_com5年前Python基础

本文实例讲述了Python判断Abundant Number的方法。分享给大家供大家参考。具体如下:

Abundant Number,中文译成:盈数(又称 丰数, 过剩数abundant number)是一种特殊的 自然数,除去它本身以外的一切正约数的和大于它本身。

介绍见百度百科: http://baike.baidu.com/view/1596350.htm

#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
def 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!"

希望本文所述对大家的Python程序设计有所帮助。

相关文章

使用python将时间转换为指定的格式方法

时间处理是在进行数据挖掘时很重要的一个方面,在参加比赛的时候很多比赛训练集给的时间和你最终要提交的时间格式是不同的。 我把我遇到的一种情况总结如下: 首先,题目给的格式是2016-09-...

python多环境切换及pyenv使用过程详解

python多环境切换及pyenv使用过程详解

1.安装pyenv    https://github.com/pyenv/pyenv-installer curl -L https://g...

Python中的多重装饰器

多重装饰器,即多个装饰器修饰同一个对象【实际上并非完全如此,且看下文详解】 1.装饰器无参数: 复制代码 代码如下: >>> def first(func): &nbs...

python3.4用循环往mysql5.7中写数据并输出的实现方法

如下所示: #!/usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "blzhu" """ python study...

Django中利用filter与simple_tag为前端自定义函数的实现方法

前言 Django的模板引擎提供了一般性的功能函数,通过前端可以实现多数的代码逻辑功能,这里称之为一般性,是因为它仅支持大多数常见情况下的函数功能,例如if判断,ifequal对比返回值...