0

I'm trying to make a code with one function that'll check for prime numbers in an array and it keeps saying that 33 is a prime number. What's wrong with my code:

def primes_nums(array):
    prime = []
    for i in array:
        for x in range(2, (i-1)):
            if i%x == 0:
                print(i,' is not a prime number')
                break
            else:
                prime.append(i)
                break
    return prime
pass
print(primes_nums([12, 33, 44, 89]))

The output comes out as:

12  is not a prime number
44  is not a prime number
[33, 89]
wjandrea
  • 28,235
  • 9
  • 60
  • 81
tommy
  • 3
  • 2
  • 1
    Go through it one step at a time. If `i%2` is not 0, then what does the code say should happen? – Ry- Feb 19 '22 at 00:32
  • Beside the point, but what's that `pass` doing there? It does literally nothing. BTW, welcome to Stack Overflow! Check out the [tour], and [ask] if you want tips. – wjandrea Feb 19 '22 at 00:32
  • @wjandrea: mabe it's meant to trick `pytest` into not raising any problems :-) – paxdiablo Feb 19 '22 at 00:40

0 Answers0