Python判斷Abundant Number的方法
本文實例講述了Python判斷Abundant Number的方法。分享給大家供大家參考。具體如下:
Abundant Number,中文譯成:盈數(shù)(又稱 豐數(shù), 過剩數(shù)abundant number)是一種特殊的 自然數(shù),除去它本身以外的一切正約數(shù)的和大于它本身。
介紹見百度百科: 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里如何用Borg pattern實現(xiàn)的單例模式
這篇文章主要介紹了聊聊python里如何用Borg pattern實現(xiàn)的單例模式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-06-06Python列表list常用內(nèi)建函數(shù)實例小結(jié)
這篇文章主要介紹了Python列表list常用內(nèi)建函數(shù),結(jié)合實例形式總結(jié)分析了Python列表list常見內(nèi)建函數(shù)的功能、使用方法及相關操作注意事項,需要的朋友可以參考下2019-10-10淺析Python中正則表達式函數(shù)search()和match()的使用
在Python中,正則表達式是處理字符串的強大工具,search()和match()是Python標準庫中re模塊中兩個常用的正則表達式方法,本文將詳細講解這兩個方法的使用,需要的可以參考一下2023-08-08