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

相关文章

Pytorch中实现只导入部分模型参数的方式

我们在做迁移学习,或者在分割,检测等任务想使用预训练好的模型,同时又有自己修改之后的结构,使得模型文件保存的参数,有一部分是不需要的(don't expected)。我们搭建的网络对保存...

python 定义n个变量方法 (变量声明自动化)

code: for i in range(100): cmd = "t%s = 1" % i exec cmd eval("t%s" % i) print t10 输出...

Selenium+Python 自动化操控登录界面实例(有简单验证码图片校验)

Selenium+Python 自动化操控登录界面实例(有简单验证码图片校验)

从最简单的Web浏览器的登录界面开始,登录界面如下: 进行Web页面自动化测试,对页面上的元素进行定位和操作是核心。而操作又是以定位为前提的,因此,对页面元素的定位是进行自动化测试的基...

Python标准库使用OrderedDict类的实例讲解

目标:创建一个字典,记录几对python词语,使用OrderedDict类来写,并按顺序输出。 写完报错: [root@centos7 tmp]# python python_ter...

Python Flask基础教程示例代码

Python Flask基础教程示例代码

本文研究的主要是Python Flask基础教程,具体介绍如下。 安装:pip install flask即可 一个简单的Flask from flask import Flask...