vendredi 24 juillet 2020

How to dynamically handle multiple options with if else statements in python

Is there a way to dynamically perform a loop to select multiple choice or is it compulsory I write each possible combinations myself?

I am creating an external application where a user can select multiple options like a, b and c. I am trying to write an if else statements for all possible combinations. Is there a way to dynamically do this or I must write each combinations all by myself?

Here is an example:

while True:
if option == 'a':
    #do something

if option == 'b':
    #do something

if option == 'c':
    #do something

if option == 'a' and option == 'b':
    #do something

if option == 'a' and option == 'c':
    #do something

if option == 'b' and option == 'a':
    #do something

and so on

Aucun commentaire:

Enregistrer un commentaire