0

I'm trying to write in python3 to determine whether a number is a prime number or not.

I was specifically demanded to only use the following method:

"Divide the input with all the positive prime number smaller than it's square root."

For example, if the given number is 33, and then I would have to divide 33 with [2,3,5] (smaller than 5.xx, the square root of 33)

Meanwhile, in the process of finding [2,3,5], I can not use any method other than the demanded one.

So my code are as follow:

def is_prime(num):
  import math
  a=math.sqrt(num)
  llist=[2,3]
  pri=0
  for i in range(2,int(a)+1):
    root=math.sqrt(i)
    for m in llist:
      if m<root:
       left=i%m
       if left!=0:
         llist.append(i)
  if num in llist:
    return True
  for m in llist:
    if num%m==0:
      return False
    if num%m!=0:
      pri=pri+1
  if pri==len(llist): 
    return True

and the code can not properly run when the input number exceed 7 figures, it just stop responding.

Apparently somewhere in my code there is an infinite loop that I can't figure out.

I'd be very grateful if someone can help me out with this one.

Aimee
  • 345
  • 1
  • 2
  • 9
  • Possible duplicate of [Python prime checker](https://stackoverflow.com/questions/18833759/python-prime-number-checker) – dstrants Apr 15 '18 at 12:24
  • Are you sure it has stopped responding or is it just taking a very long time? Have you left it running overnight? – rossum Apr 15 '18 at 16:27
  • I'm not really sure.....because it just stops compiling itself, I cant left it run overnight even if i want to qq – Aimee Apr 15 '18 at 18:04

0 Answers0