6/15 is_prime(4) returns None instead of False


#1

I am currently stuck at the the is_prime exercise. Below you can read what I tried so far...

I get this error message:

"Oops, try again. Your function fails on is_prime(4). It returns None when it should return False."

I tried to debug it by printing the answer to me, but when I do this it returns the right answer.
I have no Idea how this is happening since it is working if I use print instead of return.
In my code below I commented out when it should return. Also for debug reasons you can choose the number.


x = int(raw_input("Choose a Number:"))
testing = range(2,x-1)
def is_prime(x):
  if x == 1 or x == 0:
    print "non Prime"
     #return False 
  elif x <= 3:
    print "Prime"
    #return True
  for n in testing:
    if x%n != 0:
      print "Prime"
      #return True
    else:
      print "non Prime"
      #return False
      break


#2

may i give a tip for debugging? Call the function sh the function actually executes:

x = int(raw_input("Choose a Number:"))
testing = range(2,x-1)
def is_prime(x):
  if x == 1 or x == 0:
    print "non Prime"
     #return False 
  elif x <= 3:
    print "Prime"
    #return True
  for n in testing:
    if x%n != 0:
      print "Prime"
      #return True
    else:
      print "non Prime"
      #return False
      break
is_prime(x)

#3

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