# Is prime differences in solution

#1

Why is there Different Results in this Code?

``````> def is_prime(x): #1st Prime Code <- i copied this somewhere in the Q&A's
>      Prime = False
>      if (x < 2):
>          Prime = False
>      elif (x == 2):
>          Prime = True
>      else:
>          for n in range(2,x):
>              if ( x % n) == 0:
>                  Prime = False
>                  break
>              else:
>                  Prime = True
>      return Prime
>
>  def is_primex(x): #2nd Prime Code i wrote but doesn't work correctly!
>      if x<2:
>         return False
>      elif x==2 or x==3:
>          return True
>      else:
>          for n in range(2,x+1):
>              if x%n==0:
>                  return False #with or without a "break" here, same result
>              else:
>                  return True
>
>  for m in (range(-20,82)): #this part is to Test and Print the differences
>      if is_prime(m) != is_primex(m): # between those 2 Codes
>          print m, is_prime(m)``````

Is_Prime(9) doesn't show the correct result
#2

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