vendredi 21 mai 2021

How to simplify long if/elif statement when using comparasion

I am trying to simplify this:

        if num < 9:
            y = 1
        elif num < 17:
            y = 2
        elif num < 25:
            y = 3
        elif num < 33:
            y = 4
        elif num < 41:
            y = 5
        elif num < 49:
            y = 6
        elif num < 57:
            y = 7
        else:
            y = 8

I haven't found a way to do this yet - can someone help me?

Aucun commentaire:

Enregistrer un commentaire