vb.net - Why does python produce a "memory error" error when calculating x > 1x10^8 primes -
i have used vb.net make equivalent program python one
from colorama import init , fore init ( autoreset = true, convert = true) first = 0 second = 1 print(first) print(second) def primes ( temp ) : loopcount in range ( 2 , temp ) : if (temp % loopcount) == 0 : return false return true while true : temp = first + second first = second second = temp if primes ( temp ) == true : print(fore.red + str(temp)) else : print(temp) raw_input("") and found vb.net greater 1x10^300 whereas python can't keep beyond 1.02x10^8. don't understand why thought python great numbers , number crunching.
fyi: colorama cross platform python library allowing colouring of text in console
your program crashes because used range when wanted xrange.
quoting doc:
this function similar range(), returns xrange object instead of list. opaque sequence type yields same values corresponding list, without storing them simultaneously. advantage of xrange() on range() [occurs when] large range used on memory-starved machine
try instead:
for loopcount in xrange ( 2 , temp ) :
Comments
Post a Comment