| | |
Python can handle Very Large Numbers
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
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)
Similar Threads
- Large numbers (C)
- How to use find to handle large number of files (Getting Started and Choosing a Distro)
- how to handle large lists? (Python)
- Large Numbers (PHP)
- variable to handle large integer (C)
| Thread Tools | Search this Thread |
Tag cloud for Python
abrupt ansi anti apache approximation array backend beginner binary book builtin calculator chmod code converter countpasswordentry curved dan08 dictionaries dictionary drive dynamic examples excel file filename float format function gui heads homework import inches input java launcher library line lines linux list lists loop mouse mysql mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame pyqt pysimplewizard python random recursion redirect refresh scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tkinter tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable windows wordgame write wxpython



