I am trying to solve problem 7 of project Euler and this is the code I have
prime = []
counter = 0
while len(prime) < 10002:
counter +=1
if counter%[i for i in range (counter)] == 0 and counter != 1:
pass
else:
prime.append(counter)
print (prime[-1])
the line
if counter%[i for i in range (counter)] == 0 and counter != 1:
doesn't work. I am aware this is not the most elegent solution and will require a huge amount of time, but I am wondering how I can write this line as a single line and get it to work.
This line of code is supposed to say divide counter by every number smaller than counter. If any value yields no remainder, then the counter is NOT prime
Btw this question doesn't really have anything to do with Euler problem 7. It just so happens I am trying to solve it and thought it might help you understand what I'm trying to achievve
Thanks