In your code, the problem is that you add a random number before checking if it's odd or even in your for
loop.
I think you're looking for something like this:
def roll(sides, times):
final_sum = 0
for i in range(times):
randnum = random.randrange(sides)
final_sum += randnum if randnum % 2 else 0
return final_sum