samedi 7 juillet 2018

if, else if, is there a better way for me to run this code?

So i am new to python,

I am trying to run this code, but considering I am using a lot of copy and paste, my instincts suggest there's an easier more simple way to write this code. Any help would be appreciated. Thanks;

row = 1 
#generating row number
#[int(x) for x in str(cardnum)]
if cardnum in range(1,22):
    row = row
elif cardnum in range(22,32):
    row += 1
elif cardnum in range(32,52):
    row += 2
elif cardnum in range(52,72):
    row += 3
elif cardnum in range(82,102):
    row += 4
elif cardnum in range(102,122):
    row += 5
elif cardnum in range(122,142):
    row += 6    
elif cardnum in range(142,162):
    row += 7
elif cardnum in range(162,182):
    row += 8
elif cardnum in range(182,202):
    row += 9

Aucun commentaire:

Enregistrer un commentaire