According to several reference,
The variance of uniformly distribution is like below:
$$\frac{1}{12} (b-a)^2$$
However, after calculating the variance from scratch:
$$\sum _{x=a}^b \frac{\left(x-\frac{a+b}{2}\right)^2}{b-a}$$
The result is this:
$$\frac{1}{12} (a-b-2) (a-b-1)$$
They are not the same.
Which is wrong?
If $X \sim \mathcal{U}(a,b)$ (where $\mathcal{U}$ denotes the continuous uniform distribution), then $f(x) = \mathbb{I}_{(a,b)}/(b-a)$ and $$ \mathbb{E}[X] = \int_a^b \frac{x\ dx}{b-a} = \frac{1}{b-a} \frac{b^2-a^2}{2} = \frac{b+a}{2}, $$ where the last step uses $b^2-a^2 = (b-a)(b+a)$.
Further, $$ \mathbb{E}[X^2] = \int_a^b \frac{x^2\ dx}{b-a} = \frac{1}{b-a} \frac{b^3-a^3}{3} = \frac{b^2+ab+a^2}{3}, $$ hence $$ \mathrm{Var}\ X = \mathbb{E}[X^2] - (\mathbb{E}[X])^2 $$ Can you plug in and finish the arithmetic?