I have two functions, let's say
def f1(arr,k):
i=k
while arr[i]==0:
i=i+1
return i
and another function
def f2(arr,arr2,k):
pr=0
if arr[k]==1:
i=k
while (pr<10 and pr>-10) and (arr2[i+1]!=2):
pr=pr+(arr2[i+1]-arr2[i])
i=i+1
if arr[k]==2:
i=k
while (pr<10 and pr>-10) and (arr[i+1]!=1):
pr=pr+(arr2[i]-arr2[i+1])
i=i+1
return i+1, pr
This output i + 1 is again used for the function f1, we do this until we reach the end of the array.
I can’t figure out how to do this.
I define a function
def final(arr):
x=0
Can someone give some direction?
EDIT: after doing what @AlexForGill answered, I get Index Out of Bounds error for f2 function
def final(arr,arr2):
x=0
plist=[]
while x < len(arr)-1:
x = f1(arr, x)
if x >= len(arr)-1:
break
x, value2 = f2(arr,arr2, x)
plist.append(value2)
return plist
source
share