dimanche 29 octobre 2017

How can I make this If Loop into a dictionary valid for Python

Am working on a fun little python project, and I am stuck trying to adapt my If loop into Dictionary, but I am just not sure how to implement this function, as I need multiple conditions to be tested.

I have Six Booleans, (bool1-bool6) that can obviously be T or F, and I need to test every possible combination of these booleans, so that I can tell my program where to draw the images.

There are 64 Possible combinations.

We can do this with 3 booleans to make it simple, There are 8 Possible combinations for 3 booleans.

If we imagine that 1=true and 0=false, then the possible combinations can be represented as such.

000
001
010
011
100
101
110
111

an if loop to represent this would be,

if (bool1==false and bool2==false and bool3==false)
      do stuff
elif (bool1==false and bool2==false and bool3==true)
     do stuff
elif (bool1==false and bool2==true and bool3==false)
     do stuff

and so on...

Please unless you can find a way to simplify this process, (understanding that I need to check ALL POSSIBLE combinations of booleans), there is no need to criticize my question. I am simply unsure of how to progress from here, and would greatly appreciate some help.

I have written out a 64 statement If Loop, and am currently working on that solution, though both myself and I'm sure my cpu would prefer a quicker method.

Aucun commentaire:

Enregistrer un commentaire