dimanche 12 juillet 2020

Is there a way to make a logical operator a variable in python?

I want to take the condition from the user (as a string or a menu to choose from it doesn't matter) but I don't know how to make the logical operator varying without explicitly mentioning all the possible cases in the script.

For example, I have 4 variables (v1, v2,v3,v4) and I want to check if some of them equal 0 according to the user input (since "and" and "or" are varying I have 8 possibilities)

If v1 == 0 and v2== 0 or v3 == 0 and v4 == 0 
If v1 == 0 or v2 == 0 and v3 == 0 or v4 == 0

And so one. Is there a way to make "and" and "or" variables? Or What is the correct way to do it?

Aucun commentaire:

Enregistrer un commentaire