Help for a beginning coder!

Hello there!

I am currently writing a program that takes an integer, n, from a user, and outputs all of the prime numbers up to and including n. I have written the following code, and am not sure where I am going wrong. For some reason, my program isn’t responding to the fact that x is going up 1 each time, and therefore isn’t working. Here is the code:

def generatePrimes():
n=int(input(‘Enter a number:’))
integer_list=list(range(2,(n+1)))
result=[2,3]
x=1
for i in range(2,(n+1)):
x=x+1
if i==(((6x)-1) or ((6x)+1)):
result.append(i)
print(result)
generatePrimes()

Please let me know where I’m going wrong, and how I can fix this!

Thanks,
Caleb

Mathematics would be too simple if checking whether a number is prime were as easy as checking that it is of the form 6n-1 or 6n+1 :wink: For instance, 25 = 6*4 + 1, but 25 = 5*5 is not prime. You want something like the sieve of Eratosthenes: Sieve of Eratosthenes - Wikipedia. Have fun!