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实现AES加密解密

python实现AES加密解密

本文实例为大家分享了python实现AES加密解密的具体代码,供大家参考,具体内容如下 (1)对于AES加密解密相关知识 (2)实现的功能就是输入0-16个字符,然后经过AES的加密解...

关于Flask项目无法使用公网IP访问的解决方式

关于Flask项目无法使用公网IP访问的解决方式

最近在折腾Python Web,在测试的时候发现,本机可以正常访问,但外网无法通过公网IP访问页面。经过各种搜索,有大致三种解决方案。 一、修改/添加安全组端口 这是第一种方案,也是能解...

django项目搭建与Session使用详解

django项目搭建与Session使用详解

前言 Django完全支持也匿名会话,简单说就是使用跨网页之间可以进行通讯,比如显示用户名,用户是否已经发表评论。session框架让你存储和获取访问者的数据信息,这些信息保存在服务器上...

连接pandas以及数组转pandas的方法

pandas转数组 np.array(pandas) 数组转pandas pandas.DataFrame(numpy) pandas连接,只是左右接上,不合并值 df...

在Python中处理列表之reverse()方法的使用教程

 reverse()方法代替逆转列表对象。 语法 以下是reverse()方法的语法: list.reverse() 参数    ...