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

相关文章

使用pip发布Python程序的方法步骤

使用pip发布Python程序的方法步骤

写过 Python 程序的小伙伴们都知道,需要 import 个非 Python 自带的软件包时,都要用到 pip 这个程序。平时我们都是用 pip,如果我们写好了一个程序,想让大家都能...

python中设置超时跳过,超时退出的方式

在工作中遇到过 个问题 执行一条代码时间过长 而且还不报错,卡死在那。还要继续执行下面代码,如何操作。 下面是个简单的实例 pip安装 第三方eventlet这个包 – pip inst...

Python实现XML文件解析的示例代码

1. XML简介 XML(eXtensible Markup Language)指可扩展标记语言,被设计用来传输和存储数据,已经日趋成为当前许多新生技术的核心,在不同的领域都有着不同的应...

一个小示例告诉你Python语言的优雅之处

比如, 我们希望希望检测"一段string是否以特定的字符串结尾?", 通常我们使用: if needle.endswith('ly') or needle.endswi...

Python之虚拟环境virtualenv,pipreqs生成项目依赖第三方包的方法

Python之虚拟环境virtualenv,pipreqs生成项目依赖第三方包的方法

virtualenv简介 含义: virtual:虚拟,env:environment环境的简写,所以virtualenv就是虚拟环境,顾名思义,就是虚拟出来的一个新环境,比如我们使用的...