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

相关文章

django 捕获异常和日志系统过程详解

这一块的内容很少, 异常使用try except即可, 日志只需要几行配置. 使用装饰器捕获方法内的所有异常 我使用装饰器来整个包裹一个方法, 捕获方法中的所有异常信息.并将其转为j...

Python简单定义与使用二叉树示例

本文实例讲述了Python简单定义与使用二叉树的方法。分享给大家供大家参考,具体如下: class BinaryTree: def __init__(self,rootObj):...

Pytorch 多块GPU的使用详解

Pytorch 多块GPU的使用详解

注:本文针对单个服务器上多块GPU的使用,不是多服务器多GPU的使用。 在一些实验中,由于Batch_size的限制或者希望提高训练速度等原因,我们需要使用多块GPU。本文针对Pytor...

python使用turtle库与random库绘制雪花

python使用turtle库与random库绘制雪花

本文实例为大家分享了python绘制雪花的具体代码,供大家参考,具体内容如下 代码非常容易理解,画着玩玩还是可以的。直接上代码 # -*- coding: utf-8 -*- """...

Python3按一定数据位数格式处理bin文件的方法

Python3按一定数据位数格式处理bin文件的方法

因为研究生阶段经常用MATLAB作图,处理数据,但是MATLAB太过于庞大,不方便,就想用python处理。 问题:我们通常处理的最原始的数据是bin文件,打开后如下所示,是按16进制形...