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连接DB2数据库

Python连接DB2数据库

在工作中遇到了这样的情况,项目中需要连接IBM的关系型数据库(DB2),关于这方面的库比较稀少,其中 ibm_db 是比较好用的一个库,网上也有教程,但是好像不准确,也不太详细,错误百出...

pip matplotlib报错equired packages can not be built解决

pip安装matplotlib 在centos6.5 64bit上用pip安装matplotlib时候报错: * The following required packages ca...

基于python代码实现简易滤除数字的方法

基于python代码实现简易滤除数字的方法

如果想从一个含有数字,汉字,字母的列表中滤除仅含有数字的字符,当然可以采取正则表达式来完成,但是有点太麻烦了,因此可以采用一个比较巧妙的方式: 1、正则表达式解决 import re...

python如何实现远程控制电脑(结合微信)

不知道大家有没有这样一个烦恼,“自己的电脑总是被别人使用,又不好意思设置密码”,所以利用python设计了一个程序来实现自由管控。 功能虽然简单,但大家可以通过其思路来实现更多的功能。...

python3 pillow生成简单验证码图片的示例

使用Python的pillow模块 random 模块随机生成验证码图片,并应用到Django项目中 安装pillow $ pip3 install pillow 生成验证码图片...