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 cx_Oracle的基础使用方法(连接和增删改查)

问题 使用python操作oracle数据库,获取表的某几个字段作为变量值使用。 使用Popen+sqlplus的方法需要对格式进行控制,通过流获取这几个字段值不简洁(个人观点……)。...

Python新手在作用域方面经常容易碰到的问题

通常,当我们定义了一个全局变量(好吧,我这样说是因为讲解的需要——全局变量是不好的),我们用一个函数访问它们是能被Python理解的:   bar = 42 def fo...

python实现在图片上画特定大小角度矩形框

python实现在图片上画特定大小角度矩形框

做图像识别的时候需要在图片中画出特定大小和角度的矩形框,自己写了一个函数,给定的输入是图片名称,矩形框的位置坐标,长宽和角度,直接输出画好矩形框的图片。 主要思想是先根据x,y坐标和长宽...

python文本数据处理学习笔记详解

python文本数据处理学习笔记详解

最近越发感觉到限制我对Python运用、以及读懂别人代码的地方,大多是在于对数据的处理能力。 其实编程本质上就是数据处理,怎么把文本数据、图像数据,通过python读入、切分等,变成一个...

Python 使用folium绘制leaflet地图的实现方法

Python 使用folium绘制leaflet地图的实现方法

leaflet为R语言提供了API很好用,这次尝试用Python使用leaflet,需要folium 安装folium pip install folium 一个小例子 imp...