I have been working on a problem that should return a list with all k-Primed numbers within a range, noted as (k, start, end).
The code I wrote until then is as follows:
def check_prime(x):
c=2
if x==2:
return True
if x==0 or x==1:
return False
while c<x:
if x%c==0:
return False
break
else:
c+=1
if c==x:
return True
def prime_divs(x):
aux=2
nums=[]
primes=[]
i=0
while aux<x/2:
if x%aux==0:
nums.append(aux)
aux+=1
while i<len(nums):
if check_prime(nums[i])==True:
primes.append(nums[i])
i+=1
return primes
def k_prime(x):
k=0
primes=prime_divs(x)
if check_prime(x)==True:
k=1
else:
while x!=1:
if x%max(primes)==0:
x=int(x/max(primes))
k+=1
else:
del primes[len(primes)-1]
return k
def count_Kprimes(k_lim, start, end):
i=start
nums=[]
while i<=end:
if k_lim==k_prime(i):
nums.append(i)
i+=1
return nums
After testing the last function, I get this error:
line 38, in k_prime
if x%max(primes)==0:
ValueError: max() arg is an empty sequence
All the other functions before count_Kprimes
work properly. Why is the last one leading to this error?