Hint:
Given two numbers A and B (both inclusive) where B > A, the sum of values between A & B is given by
B(B + 1)/2 - (A - 1)A/2
=(B^2 + B - A^2 + A)/2
=((B - A)(B + A) + (B + A))/2
=(B + A)(B - A + 1)/2
If A & B are both exclusive, then replace B with B - 1 and A with A + 1. The rest I leave it for you as an exercise
Read through the Python Expression to translate the mathematical expression to Python Code
Note
Unfortunately, SO does not support MathJax or else the above expression could had been formatted better