You can use a dictionary that matches dice with random.randint call random.randint :
>>> mapping = { ... 0: [0, 4, 0, 4],
Further, using collections.defaultdict , you do not need to handle the else case specifically.
from collections import defaultdict dice = random.randint(0, 3) ans = network.receive() dice_random_mapping = defaultdict(lambda: [4, 9, 4, 9], { # else 0: [0, 4, 0, 4], # if dice == 1 1: [0, 4, 4, 9], # elif dice == 2 2: [4, 9, 0, 4], # elif dice == 3 }) if ans == None: start1, stop1, start2, stop2 = dice_random_mapping[dice] guess = str(random.randint(start1, stop1))+','+str(random.randint(start2, stop2))
source share