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

相关文章

Pycharm+Python+PyQt5使用详解

Pycharm+Python+PyQt5使用详解

1,打开cmd安装PyQt5 pip install pyqt5 2,PyQt5不再提供Qt Designer等工具,所以需要再安装pyqt5-tools pip instal...

Python创建系统目录的方法

本文实例讲述了Python创建系统目录的方法。分享给大家供大家参考。具体如下: Python2 mkdir在没有上级目录时创建会失败.该方法可以创建多级目录。 /temp/gapgers...

python多行字符串拼接使用小括号的方法

多行字符串拼接使用小括号 s = ('select *' 'from atable' 'where id=888') print s, type(s) #输出 select...

在Python中构建增广矩阵的实现方法

麻烦的 # TODO 构造增广矩阵,假设A,b行数相同 def augmentMatrix(A, b): if(len(A) != len(b)): raise 'The...

Django框架 Pagination分页实现代码实例

一、自定义分页 1、基础版自定义分页 data = [] for i in range(1, 302): tmp = {"id": i, "name": "alex-{}...