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

相关文章

python连接池实现示例程序

复制代码 代码如下:import socketimport Queueimport threading def worker():    while Tru...

python文件操作相关知识点总结整理

本文汇总了python文件操作相关知识点。分享给大家供大家参考,具体如下: 总是记不住API。昨晚写的时候用到了这些,但是没记住,于是就索性整理一下吧: python中对文件、文件夹(文...

Python封装成可带参数的EXE安装包实例

最近有一个小项目,有如下的需求: 将某几个源码文件夹进行打包,文件夹内有py文件、dll文件、exe文件等各种文件类型 打包生成的安装包,在进行安装的时候,应该能够带有参数,对配置文件进...

一张图带我们入门Python基础教程

一张图带我们入门Python基础教程

啄木鸟社区上原始翻译后绘制的,最早这个图是出现在(链接已失效) “这个图太棒了,有编程基础的人一下子就了解 Python 的用法了。真正的 30 分钟上手。”Buzz by http:/...

python的socket编程入门

Flask或者其他框架都是封装的比较完善,我们可以不去关注路由、SESSION等到底是怎么实现的,现在我们使用socket来实现一个带有注册、登录功能的To do网站,这样能对后端框架了...