hey this is a code that works fine. i am using in a bigger code and the program gives quick answer for like 999999 or 9999999.
prime=[2,3,5]
f=7
def next_prime(f): #whenever called, measures the next prime of the list and returns it
j=len(prime)
while j==len(prime):
for x in prime:
if f%x==0:
f+=2
break
else:
prime.append(f)
return f
But if i modify the code a little bit (I want add the condition that x should be less than f**.5), the program gives no results.
prime=[2,3,5]
f=7
main=[]
power=[]
def next_prime(f):
j=len(prime)
while j==len(prime):
for x in prime:
if (x<int(f**.5)+1) and f%x==0:
f+=2
break
else:
prime.append(f)
return f
Where is the mistake?
fpassed as a parameter, whileprimeis slips in as a global variable? Isn'tf=next_prime(f)the only meaningful way of calling this function?