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

相关文章

Python多线程扫描端口代码示例

本文代码实现Python多线程扫描端口,具体实现代码如下。 #coding:utf-8 import socket import thread import time socket....

vim自动补全插件YouCompleteMe(YCM)安装过程解析

Vim是全平台上一个高度可拓展的编辑器。它本身只是一个简陋的编辑器,但是因为有各种插件而变得强大。使用Vim编写代码就不免遇到代码补全的问题。常用的代码补全插件有两个:日本人shougo...

python3访问sina首页中文的处理方法

复制代码 代码如下:"""如果只用普通的import urllib.requesthtml = urllib.request.urlopen("http://www.sina.com")...

python docx 中文字体设置的操作方法

最近用到了docx生成word文档,docx本身用起来很方便,自带的各种样式都很好看,美中不足的就是对中文的支持不够好。在未设置中文字体的时候,生成的文档虽然可以显示中文,但是笔画大小不...

pandas dataframe添加表格框线输出的方法

pandas dataframe添加表格框线输出的方法

将dataframe添加到texttable里面,实现格式化输出。 data=[{"name":"Amay","age":20,"result":80}, {"name":"T...