6. is_prime alternative


#1




I wrote this as an alternative to whatever the instruction says. It's short but gets MemoryError on numbers over 3 million.


def is_prime(x):
    divisions = 0
    for n in range(1, x+1):            
        if x%n == 0:
            divisions += 1
    return divisions == 2


#2

try xrange instead


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.