I'm relatively new to programming and decided to, on my own time, mess around and create a few basic functions of my own. I'm sure plenty of other variations exist, but I wanted to just make them my own way to learn. I am currently trying to write a function that displays all prime numbers within a certain Max value as a limit in a list. However, I seem to have a problem with my if statement in the while loop. I keep getting list index out of range and I am confused as to why. If someone could explain to me the reason, I would be incredibly grateful.
#A function that will hopefully display all primes
def showPrimes(lim):
"""Displays all primes within the range (1, lim]
"""
fullRange = list(range(2, lim + 1))
q = 0
k = 2
while(q != lim):
if(fullRange[q] % (q + 2) == 0 and fullRange[q] != (q + 2)):
fullRange.pop(q)
q = q + 1
return fullRange