Edit: This is not homework, I am a chemical engineering student and a math minor. I'm doing programming on the side to help me automate certain calculations later in my career. Also always had a healthy interest in programming. I just read the not doing homework for people sticky at the top and want to throw out there i'm not a computer programming student.
I'm creating a program to create list of prime numbers code. It has taught me a good amount about recursions statements and how while statements can be used to maximize performance for given recursion limits.
My problem is I can only search a range of ~ 1000 numbers before the recursion limit is reached. I know there is some basic improvements I can do but my current concerns:
1. The program recurs the program Prime(x) with program Prime(x+1) to check the next x value across the interval [x,x+970]. Finding all prime numbers over that interval. However, I can't find out how to define the upper bound x+970 since recurring Prime(x+1) increases the upper bound.
So how can I create a fixed upper bound with only one variable being inputted, x.
2. Is their a way to have the program run for the interval clear the stack, than run the next interval [x+971,x+970+971] if an interval greater than the recursion limit was desired? Till a single number is too large for the platform I would expect there to be a way around the recursion limit.
This is one of my first independent programs and I just couldn't find good answers to these questions.
def Prime(x): n=2 [B] if x > 972:[/B] #My upper limit is 972 and my lower limit is x, print "end" #how do I make the upper limit a function of x elif x == 1: # when I have to recur Prime(x+1)? Prime(x+1) elif x == 2: print (2) Prime(x+1) elif x <= 0: print ("Number must be a positive integer") else: while n < n+1: if n > int(x/n): print(x) break elif x%n==0: break else: n=n+1 Prime(x+1)