dimanche 22 mars 2020

Invalid syntax python problem (if statement many actions)

I am encountering a problem on my python code. I'm trying to increment and decrement two values after an if statement. However, this couldn't be achieved (Error: invalid syntax). Knowing that when I increment only a single value (e.g. A_p), it works well. Does the error come from the and operator? Is there a way to perform multiple actions after an if statement?

Thank you.

Omer

k1 = 0.2
k2 = 0.2 
Delta_t = 2


A_p = 4
B_p = 3


list_nm = [0.800, 0.801, 0.752, 0.661, 0.169, 0.956, 0.949, 0.003, 0.201, 0.291, 0.615, 0.131, 0.241, 0.685, 0.116, 0.241, 0.849]

for i in range(7):
    if list_nm[i] < (A_p/7):
        print("Particle A was choosen")
        if list_nm[i] < k1*Delta_t:
            A_p -= 1 and B_p += 1
        else:
            A_p = A_p and B_p = B_p
    elif list_nm[i] < (B_p/7):
        print("Particle B was choosen")
        if list_nm[i] < k2*Delta_t:
            A_p +=1 and B_p -=1
        else:
            A_p = A_p and B_p = B_p
    else:
        print("No choice was made")
        A_p = A_p and B_p = B_p
print(B_p)

Aucun commentaire:

Enregistrer un commentaire