isprime function - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32) +---- Thread: isprime function (/showthread.php?tid=4969) |
isprime function - nevets04 - 02-23-2010 I made this function to check whether a number was prime or not. This was developed using codepad.org to test it during my 15 minute study hall. So it's simple, but it does work as far as I can see. Code: #!/usr/bin/env python RE: isprime function - uber1337 - 02-23-2010 Seems to be effective, you could have shortened it a bit though Code: #!/usr/bin/env python RE: isprime function - Fallen - 04-05-2010 (02-23-2010, 06:46 PM)uber1337 Wrote: Code: return False if n in [1, 4, 6, 8, 9, 10] else True You are aswell RE: isprime function - uber1337 - 04-06-2010 (04-05-2010, 06:15 PM)Fallen Wrote:LOL you really need to stop shortening things lol. Why don't you just use C++ and have a full length program on one line? RE: isprime function - symetrik - 04-18-2010 Quote: Defeated by: Code: if isprime(x) and x > 11: isprime(x**x) For example: Code: if isprime(13) and x > 11: # Will return true, as 13 is a prime and is larger than 10. RE: isprime function - wat - 05-05-2010 Your function assumes that all composite numbers above 10 are divisible by a number smaller than 10; not true. Here's an article explaining some of the intricacies that go into finding prime numbers . Keep in mind that the first method mentioned could be optimized more by only checking numbers smaller than sqrt(num) instead of num / 2. |