For a school assignment I have to choose two random integers from 0 to 20 and its result (through sub or add which also chooses random) must be in range 0 to 20. For integers and operations I used:
def random():
op={"-": operator.sub, "+": operator.add}
a = random.randint (0,20)
b = random.randint (0,20)
ops = random.choice(list(op.keys()))
answer=op[ops](a,b)
return answer
Source link for the above code: How can I randomly choose a maths operator and ask recurring maths questions with it?
But i have no idea how to use it in such a way that it can give a result only in range of 0 to 20. Python v3.0 beginner.