Scientists and deficit spenders like to use Python because it can handle very large numbers. I decided to give it a test with factorials. Factorials reach astronomical levels rather quickly. In case you can't quite remember, the factorial of 12 is !12 = 1*2*3*4*5*6*7*8*9*10*11*12 = 479001600, that is 479 million and some change! After that languages like C++ start to fizzle quickly! At !16 we get past the nations debt. Python can handle that and more! I stopped at !69 only because the display started to wrap the line. The result has 98 digits in it, I thought I made my point anyway.
# check the numeric range of Python with huge factorials # factorial(69) still checks out accurately! Has 98 digits in it! # 171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000 # tested with Python24 vegaseat 01aug2005 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)
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.