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

相关文章

Python3常见函数range()用法详解

0X01函数说明: python range() 函数可创建一个整数列表,一般用在 for 循环中。 0X02函数语法: range(start,stop[,step]) star...

使用Python实现一个栈判断括号是否平衡

栈(Stack)在计算机领域是一个被广泛应用的集合,栈是线性集合,访问都严格地限制在一段,叫做顶(top)。 举个例子,栈就想一摞洗干净的盘子,你每次取一个新盘子,都是放在这一摞盘子的最...

你眼中的Python大牛 应该都有这份书单

你眼中的Python大牛 应该都有这份书单

在最新一期的话题中,80%读者认为Python是最好的编程语言,知乎上类似的问题也很多,例如如何入门Python?如何3个月内入门Python?虽然现在可以学习的Python途径...

Pandas的read_csv函数参数分析详解

函数原型 复制代码 代码如下:pd.read_csv(filepath_or_buffer, sep=',', delimiter=None, header='infer', name...

python实现图书管理系统

本文实例为大家分享了python实现图书管理系统的具体代码,供大家参考,具体内容如下 import mysql.connector import sys, os import tim...