python处理大数字的方法

转载  2015-05-27   作者:依山带水   我要评论

这篇文章主要介绍了python处理大数字的方法,涉及Python递归操作的相关技巧,需要的朋友可以参考下

本文实例讲述了python处理大数字的方法。分享给大家供大家参考。具体实现方法如下:

def getFactorial(n):
  """returns the factorial of n"""
  if n == 0:
    return 1
  else:
    k = n * getFactorial(n-1)
    return k
for k in range(1, 70):
  print "factorial of", k,"=", getFactorial(k)

运行结果如下:

factorial of 1 = 1
factorial of 2 = 2
factorial of 3 = 6
factorial of 4 = 24
factorial of 5 = 120
factorial of 6 = 720
factorial of 7 = 5040
factorial of 8 = 40320
factorial of 9 = 362880
factorial of 10 = 3628800
factorial of 11 = 39916800
factorial of 12 = 479001600
factorial of 13 = 6227020800
factorial of 14 = 87178291200
factorial of 15 = 1307674368000
factorial of 16 = 20922789888000
factorial of 17 = 355687428096000
factorial of 18 = 6402373705728000
factorial of 19 = 121645100408832000
factorial of 20 = 2432902008176640000
factorial of 21 = 51090942171709440000
factorial of 22 = 1124000727777607680000
factorial of 23 = 25852016738884976640000
factorial of 24 = 620448401733239439360000
factorial of 25 = 15511210043330985984000000
factorial of 26 = 403291461126605635584000000
factorial of 27 = 10888869450418352160768000000
factorial of 28 = 304888344611713860501504000000
factorial of 29 = 8841761993739701954543616000000
factorial of 30 = 265252859812191058636308480000000
factorial of 31 = 8222838654177922817725562880000000
factorial of 32 = 263130836933693530167218012160000000
factorial of 33 = 8683317618811886495518194401280000000
factorial of 34 = 295232799039604140847618609643520000000
factorial of 35 = 10333147966386144929666651337523200000000
factorial of 36 = 371993326789901217467999448150835200000000
factorial of 37 = 13763753091226345046315979581580902400000000
factorial of 38 = 523022617466601111760007224100074291200000000
factorial of 39 = 20397882081197443358640281739902897356800000000
factorial of 40 = 815915283247897734345611269596115894272000000000
factorial of 41 = 33452526613163807108170062053440751665152000000000
factorial of 42 = 1405006117752879898543142606244511569936384000000000
factorial of 43 = 60415263063373835637355132068513997507264512000000000
factorial of 44 = 2658271574788448768043625811014615890319638528000000000
factorial of 45 = 119622220865480194561963161495657715064383733760000000000
factorial of 46 = 5502622159812088949850305428800254892961651752960000000000
factorial of 47 = 258623241511168180642964355153611979969197632389120000000000
factorial of 48 = 12413915592536072670862289047373375038521486354677760000000000
factorial of 49 = 608281864034267560872252163321295376887552831379210240000000000
factorial of 50 = 30414093201713378043612608166064768844377641568960512000000000000
factorial of 51 = 1551118753287382280224243016469303211063259720016986112000000000000
factorial of 52 = 80658175170943878571660636856403766975289505440883277824000000000000
factorial of 53 = 4274883284060025564298013753389399649690343788366813724672000000000000
factorial of 54 = 230843697339241380472092742683027581083278564571807941132288000000000000
factorial of 55 = 12696403353658275925965100847566516959580321051449436762275840000000000000
factorial of 56 = 710998587804863451854045647463724949736497978881168458687447040000000000000
factorial of 57 = 40526919504877216755680601905432322134980384796226602145184481280000000000000
factorial of 58 = 2350561331282878571829474910515074683828862318181142924420699914240000000000000
factorial of 59 = 138683118545689835737939019720389406345902876772687432540821294940160000000000000
factorial of 60 = 8320987112741390144276341183223364380754172606361245952449277696409600000000000000
factorial of 61 = 507580213877224798800856812176625227226004528988036003099405939480985600000000000000
factorial of 62 = 31469973260387937525653122354950764088012280797258232192163168247821107200000000000000
factorial of 63 = 1982608315404440064116146708361898137544773690227268628106279599612729753600000000000000
factorial of 64 = 126886932185884164103433389335161480802865516174545192198801894375214704230400000000000000
factorial of 65 = 8247650592082470666723170306785496252186258551345437492922123134388955774976000000000000000
factorial of 66 = 544344939077443064003729240247842752644293064388798874532860126869671081148416000000000000000
factorial of 67 = 36471110918188685288249859096605464427167635314049524593701628500267962436943872000000000000000
factorial of 68 = 2480035542436830599600990418569171581047399201355367672371710738018221445712183296000000000000000
factorial of 69 = 171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000

希望本文所述对大家的Python程序设计有所帮助。

相关文章

  • Python yield 小结和实例

    Python yield 小结和实例

    yield的作用就是把一个函数变成一个 generator,带有 yield 的函数不再是一个普通函数,Python 解释器会将其视为一个 generator(不知道什么是generator要先去理解一下Python的generator的了)
    2014-04-04
  • Python中的推导式使用详解

    Python中的推导式使用详解

    这篇文章主要介绍了Python中的推导式使用详解,本文分别讲解了列表推导式、字典推导式、集合推导式使用实例,需要的朋友可以参考下
    2015-06-06
  • Python中的random()方法的使用介绍

    Python中的random()方法的使用介绍

    这篇文章主要介绍了Python中的random()方法的使用,是Python入门的基础知识,需要的朋友可以参考下
    2015-05-05
  • python类的继承实例详解

    python类的继承实例详解

    这篇文章主要介绍了python类的继承实例详解的相关资料,需要的朋友可以参考下
    2017-03-03
  • 零基础写python爬虫之爬虫编写全记录

    零基础写python爬虫之爬虫编写全记录

    前面九篇文章从基础到编写都做了详细的介绍了,第十篇么讲究个十全十美,那么我们就来详细记录一下一个爬虫程序如何一步步编写出来的,各位看官可要看仔细了
    2014-11-11
  • Python OpenCV实现图片上输出中文

    Python OpenCV实现图片上输出中文

    这篇文章主要为大家详细介绍了Python OpenCV实现图片上输出中文,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-01-01
  • python 调用c语言函数的方法

    python 调用c语言函数的方法

    本篇文章主要介绍了python 调用c语言函数的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-09-09
  • 浅谈function(函数)中的动态参数

    浅谈function(函数)中的动态参数

    下面小编就为大家带来一篇浅谈function(函数)中的动态参数。小编觉得听不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-04-04
  • python操作ssh实现服务器日志下载的方法

    python操作ssh实现服务器日志下载的方法

    这篇文章主要介绍了python操作ssh实现服务器日志下载的方法,涉及Python建立ssh连接并下载服务器日志的相关技巧,需要的朋友可以参考下
    2015-06-06
  • Python操作MySQL简单实现方法

    Python操作MySQL简单实现方法

    这篇文章主要介绍了Python操作MySQL简单实现方法,通过一个简单的实例讲述了Python针对mysql数据库的增删改查技巧,需要的朋友可以参考下
    2015-01-01

最新评论