May-11-2018, 01:00 PM
Hello ! =)
I'm new is Python. I would like create a function which is responsible for filling a list with 0, 1, -1 values depending on 4 other list values. I wrote a code, but it doesn't work, I don't understand why. Any of your help is welcome. Thank you!
I'm new is Python. I would like create a function which is responsible for filling a list with 0, 1, -1 values depending on 4 other list values. I wrote a code, but it doesn't work, I don't understand why. Any of your help is welcome. Thank you!
# Position function def Startegy(A, B, C, D): # Create a vector of positions position = [] position.append(0) # If previous position is 0 for i in A: if position(i-1) == 0: if A(i) > B(i) > C(i) > D(i): position(i) == 1 if A(i) < B(i) < C(i) < D(i): position(i) ==-1 # If previous position is -1 elif position(i-1) == -1: if A(i) > B(i) > C(i) > D(i): position(i) == 1 if A(i) < B(i) < C(i) < D(i): position(i) == -1 # If previous position is 1 elif position(i-1) == 1: if A(i) > B(i) > C(i) > D(i): position(i) == 1 if A(i) < B(i) < C(i) < D(i): position(i) == -1 # In other case keep the position else: position(i) == position(i-1) return position A = [1,5,6,9,10,15] B = [1,4,5,8,12,10] C = [1,3,4,7,8,6] D = [1,2,3,4,5,5] res = Startegy(A,B,C,D) print(res)