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

相关文章

PyQt5+requests实现车票查询工具

PyQt5+requests实现车票查询工具

PyQt5+requests实现一个车票查询工具,供大家参考,具体内容如下 结构图 效果图 思路 1、search(QPushButton)点击信号(clicked)连接到自定义的槽...

浅析Python中的for 循环

Python for 和其他语言一样,也可以用来循环遍历对象,本文章向大家介绍Python for 循环的使用方法和实例,需要的朋友可与参考一下。 一个循环是一个结构,导致第一个程序要重...

python retrying模块的使用方法详解

前言 我们在写爬虫的过程中,经常遇到爬取失败的情况,这个时候我们一般会通过try块去进行重试,但是每次都写那么一堆try块,真的是太麻烦,所以今天就来说一个比较pythonic的模块,r...

python实现一个点绕另一个点旋转后的坐标

python实现一个点绕另一个点旋转后的坐标

如下所示: (x,y)为要转的点,(pointx,pointy)为中心点,如果顺时针角度为angle srx = (x-pointx)*cos(angle) + (y-pointy)*s...

Python机器学习之scikit-learn库中KNN算法的封装与使用方法

Python机器学习之scikit-learn库中KNN算法的封装与使用方法

本文实例讲述了Python机器学习之scikit-learn库中KNN算法的封装与使用方法。分享给大家供大家参考,具体如下: 1、工具准备,python环境,pycharm 2、在机器学...