samedi 16 décembre 2017

python - do action based on whichever # gets picked

Lets say i have this code at the bottom. Its really annoying if I need to change something. Is there an easier to way write this code? Something with arrays or idk? I'm pretty new to Python so any help would be appreciated.

    ti = randint(1,10)

    if ti == 1:
        something.action()

    if ti == 2:
        something2.action()

    if ti == 3:
        something3.action()

    if ti == 4:
        something4.action()

    if ti == 5:
        something5.action()




Aucun commentaire:

Enregistrer un commentaire