1

I am trying to code a prime number finder in python. This is not some kind of assignment, but purely for fun. Somehow, the program gives me wrong answers! But I really cant find out why... maybe you guys could help me? I would be really grateful.

My code:

def is_prime(n):
    if n == 0 or n == 1:
        print(n, "is prime")
        return true
    else:
        for i in range(2, ((n+1)/2)):
            if n%i == 0:
                print(n, " isn't prime.")
                return false
            else:
                print(n, " is prime.")
                return true
user226447
  • 55
  • 3

1 Answers1

1

Hint: your program concludes that a number is prime as soon as it sees that the number is not divisible by two.

NPE
  • 486,780
  • 108
  • 951
  • 1,012