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控制windows剪贴板,向剪贴板中写入图片的实例

如下所示: from ctypes import * import os import win32con,win32clipboard aString=windll.user32....

Python 脚本拉取 Docker 镜像问题

Python 脚本拉取 Docker 镜像问题

好久没有介绍小工具了,今天碰到一个,简单粗糙但是有用的一个,这个工具有多简单粗糙呢?证据有二: 连 Python shebang 都没有; 简单到原创 300 字都很难凑够。 言归正传:...

Python实现二维数组输出为图片

对于二维数组,img_mask [[ 0 0 0 ..., 7 7 7] [ 0 0 0 ..., 7 7 7] [ 0 0 0 ..., 7 7 7] ..., [266...

python中dict()的高级用法实现

python中dict()的高级用法实现

collections中defaultdict的用法 一、字典的键映射多个值 将下面的列表转换成字典 一个字典就是一个键对应一个单值得映射,而上面的列表中有相同的键,如果你想要一个键映...

python自动化测试实例解析

本文实例讲述了python自动化测试的过程,分享给大家供大家参考。 具体代码如下: import unittest ##############################...