Python判断Abundant Number的方法

yipeiwu_com6年前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程序设计有所帮助。

相关文章

Django stark组件使用及原理详解

Django stark组件使用及原理详解

 stark组件是仿照django的admin模块开发的一套组件,它的作用是在网页上对注册的数据表进行增删改查操作 一、配置 1、创建stark应用,在settings.py...

Python中暂存上传图片的方法

很简单的代码,记录一下。 复制代码 代码如下:     import Image     image = Image.open...

kNN算法python实现和简单数字识别的方法

kNN算法python实现和简单数字识别的方法

本文实例讲述了kNN算法python实现和简单数字识别的方法。分享给大家供大家参考。具体如下: kNN算法算法优缺点: 优点:精度高、对异常值不敏感、无输入数据假定 缺点:时间复杂度和空...

python 文件操作api(文件操作函数)

python中对文件、文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块。 得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 返回指定目录下...

python多线程之事件Event的使用详解

前言 小伙伴a,b,c围着吃火锅,当菜上齐了,请客的主人说:开吃!,于是小伙伴一起动筷子,这种场景如何实现 Event(事件) Event(事件):事件处理的机制:全局定义了一个内置标志...