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操作多维数组输出和矩阵运算。分享给大家供大家参考,具体如下: 在许多编程语言中(Java,COBOL,BASIC),多维数组或者矩阵是(限定各维度的大小)预先定...

python显示生日是星期几的方法

本文实例讲述了python显示生日是星期几的方法。分享给大家供大家参考。具体实现方法如下: # find the day of the week of a given date #...

Python实现简单求解给定整数的质因数算法示例

本文实例讲述了Python实现简单求解给定整数的质因数算法。分享给大家供大家参考,具体如下: 接着做题遇到求解质因数分解的问题,思想很简单,就是需要遍历从1到该整数本身,并且判断当数字为...

python设定并获取socket超时时间的方法

python写法 import socket def test_socket_timeout(): s = socket.socket(socket.AF_INET,...

Python中sorted()排序与字母大小写的问题

今天我在练习python时,对字典里的键用sorted排序时发现并没有按照预期排序 研究后发现字母大小写会影响排序 首先创建一个字典,键里面的首字母有大写有小写 favorite_...