Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
isprime function
#1
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
def isprime(n):
    if n > 10:
        if n%2 == 0 or n%3 == 0 or n%4 == 0 or n%5 == 0 or n%6 == 0 or n%7 == 0 or n%8 == 0 or n%9 == 0 or n%10 == 0:
            return False
        else:
            return True
    if n <= 10:
        if n == 2 or n == 3 or n == 5 or n == 7:
            return True
        if n == 1 or n == 4 or n == 6 or n ==8 or n == 9 or n == 10:
            return False
Reply


Messages In This Thread
isprime function - by nevets04 - 02-23-2010, 01:54 PM
RE: isprime function - by uber1337 - 02-23-2010, 06:46 PM
RE: isprime function - by Fallen - 04-05-2010, 06:15 PM
RE: isprime function - by uber1337 - 04-06-2010, 12:03 PM
RE: isprime function - by symetrik - 04-18-2010, 11:08 AM
RE: isprime function - by wat - 05-05-2010, 05:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic filter function uber1337 1 967 08-13-2010, 10:59 AM
Last Post: xerotic

Forum Jump:


Users browsing this thread: 7 Guest(s)