I am currently trying to build a function that finds the second divisor of a number (n) and returns the index of the second divisor WITHOUT calling the build-in index function.
xs is a list and n is the number to be divided
example would be: locate_second_divisor([20,3,4,2],12)
yields 2
My current code
count=0
def locate_second_divisor(xs,n):
count=0
for num in xs:
if n % num==0:
count+=1
if count==2:
return
At return, I need to write the index of the second divisor but I can't think of how to do it without calling index.
This is not a duplicate question as I am not allowed to use ANY built in functions. I can only use append, int, float, str, and loops with booleans and operators. I cannot use enumerate like similar questions can. I need some sort of way around the built in functions.
Updated code (only fails because I have to include None if there is no second divisor)
def locate_second_divisor(xs,n): count=0 index=0 for num in xs: if (n % num)==0: count+=1 if count ==2: return index else: return None