So, I've made this code:
y = 10
prime_num = [x for x in range(1,y) if y%x != 0]
It's returned me:
[3, 4, 6, 7, 8, 9]
The purpose of this code is to generate prime numbers within 1 to 10, it returned me an odd number which I do not quiet get. I was expecting this to work since my list comprehension was an attempted replica of:
def is_prime(x):
if x < 2:
return False
else:
for n in range(2, x-1):
if x % n == 0:
return False
return True
Which I've created from codecademy, I've simply changed "x%n == 0" to "x%n != 0".