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

相关文章

Python常用库大全及简要说明

环境管理 管理 Python 版本和环境的工具 p:非常简单的交互式 python 版本管理工具。官网 pyenv:简单的 Python 版本管理工具。官网 Vex:可以在虚拟环境中...

python字符串与url编码的转换实例

主要应用的场景 爬虫生成带搜索词语的网址 1.字符串转为url编码 import urllib poet_name = "李白" url_code_name = urllib.quo...

对python中数据集划分函数StratifiedShuffleSplit的使用详解

对python中数据集划分函数StratifiedShuffleSplit的使用详解

文章开始先讲下交叉验证,这个概念同样适用于这个划分函数 1.交叉验证(Cross-validation) 交叉验证是指在给定的建模样本中,拿出其中的大部分样本进行模型训练,生成模型,留小...

使用pdb模块调试Python程序实例

在Python中,语法错误可以被Python解释器发现,但逻辑上错误或变量使用错误却不容易发现,如果结果没有符合预期,则需要调试,一个很好的调试工具:Python自带的pdb模块。pdb...

Python中的random()方法的使用介绍

 random()方法返回一个随机浮点数r,使得0是小于或等于r 以及r小于1。 语法 以下是random()方法的语法: random ( ) 注意:此函数是无法直...