def isPrime(num,div=2):
        return True
    elif(num % div == 0):
        return False
        return isPrime(num,div+1)

Recommended Answers

All 2 Replies

Probably the worst isPrime() function I've ever seen. If num is above 1000000, you are going to stack 1000000 recursive calls ! Python comes with a recursion limit

>>> import sys
>>> sys.getrecursionlimit()

which means that your code will fail. The limit can be changed, but in every day programming, it does not need to.

There is no question in your post. Is it a code snippet ?

Yes, it is worse then the infamous:

not re.match(r"^1?$|^(11+?)\1+$", "1" * number_to_test)

There is nothing wrong with this algo. But computers (more precisely: functions using stack in the operating system) are not built the way, they can process this program efficiently. It is a leaking abstraction. Google it.

commented: ugly code :) +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.