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

相关文章

配置 Pycharm 默认 Test runner 的图文教程

配置 Pycharm 默认 Test runner 的图文教程

如下所示: 由图中可见,当前使用的是 unittest 测试框架 修改方式如下: 以上这篇配置 Pycharm 默认 Test runner 的图文教程就是小编分享给大家的全部...

Python实现约瑟夫环问题的方法

本文实例讲述了Python实现约瑟夫环问题的方法。分享给大家供大家参考,具体如下: 题目:0,1,...,n-1这n个数字排成一个圆圈,从数字0开始每次从这个圆圈里删除第m个数字。求出这...

在Python中使用pngquant压缩png图片的教程

说到png图片压缩,可能很多人知道TinyPNG这个网站。但PS插件要钱(虽然有破解的),Developer API要连到他服务器去,不提网络传输速度,Key也是有每月限制的。 &nbs...

python 对给定可迭代集合统计出现频率,并排序的方法

给定一个可迭代sequence,对其中的值进行出现次数统计: 方法1: def get_counts(sequence): counts = {} for x in sequen...

python发送HTTP请求的方法小结

本文实例讲述了python发送HTTP请求的方法。分享给大家供大家参考。具体如下: 这里包含 Python 使用 GET/HEAD/POST 方法进行 HTTP 请求 1. GET 方法...