mardi 30 mars 2021

How can I combine these two if statements?

Here're two if statements I have (using Python):

if eval0 < eval1 and (theta/pi)%4 < 2:
    gamma *= (-1)
elif eval0 > eval1 and (theta/pi + 2)%4 < 2:
    gamma *= (-1)

I'm trying to shorten the code, so one way I can think of is

if (eval0 < eval1 and (theta/pi)%4 < 2) or (eval0 > eval1 and (theta/pi + 2)%4 < 2):
    gamma *= (-1)

Is there a better way I can do that? Thanks!!

Aucun commentaire:

Enregistrer un commentaire