class Sieve:
def __init__(self, digit):
self.digit = []
numbers = [True]*digit
if digit <= -1:
raise RuntimeError("Cannot use negative values.")
numbers[0] = False
numbers[1] = False
def findPrimes(self):
for i in range(len(self.digit)):
if numbers[i]:
j = (i+i)
while (j < len(numbers)):
numbers[j] = False
j += i
print(numbers)
This is my first post on stackoverflow and after trying for a long time figuring out what to do and searching the internet, I'm afraid I have to ask here. My program is supposed to find all prime numbers given any number in the initial class. I was trying to check my findPrimes(), but I was having a difficult time trying to get the values to print. I keep getting the error "numbers is not defined". Am I supposed to define it outside of findPrimes? Or is there a specific way I can call numbers from init to findPrimes? Thank you!