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基于递归算法求最小公倍数和最大公约数示例

本文实例讲述了Python基于递归算法求最小公倍数和最大公约数。分享给大家供大家参考,具体如下: # 最小公倍数 def lcm(a, b, c=1): if a * c % b...

python 容器总结整理

python 容器总结整理 list 可变数组 tuple 不可变数组 dict 键值对(key-value)的字典(dictionary) 初始化: a={‘lyt':90}...

Python用模块pytz来转换时区

前言 最近遇到了一个问题:我的server和client不是在一个时区,server时区是EDT,即美国东部时区,client,就是我自己的电脑,时区是中国标准时区,东八区。处于测试需要...

Java实现的执行python脚本工具类示例【使用jython.jar】

本文实例讲述了Java实现的执行python脚本工具类。分享给大家供大家参考,具体如下: 这里java中执行python脚本工具类,需要使用jython.jar java中执行pytho...

对python 自定义协议的方法详解

前面说到最近在写python的一些东西,然后和另外一位小伙伴定义了协议,然后昨天我有一部分东西没理解对,昨天上午我自己重写了一遍接收和发送的全部逻辑,昨天下午补了压力测试的脚本,自测没问...