Help with finding expectancy So I have $x\sim U(\{1,2,..., 20\})$
and I need to find $E(x^2)$. 
I have tried searching our textbook but could not really understand the logic behind the steps they showed.
Where am i supposed to start solving something like this?

$x$ is uniformly distributed on the set $\{1, 2, \dots, 20\} $, so there are the same number of $1$'s as $2$'s as $3$'s, etc. Now, the variable we are investigating to find the expected value is $x^2$. So, the set $\{1, 4, 9, \dots, 400\}$ of squares will be uniformly distributed. The expected value is the average of that set. As Siong said, that average can be calculated using the formula $$\frac 1{n}\sum_{i=1}^{n}i^2=\frac{n(n+1)(2n+1)}{6\times n}$$ where $n=20$ in this case. 
The formula $\sum_{i=1}^ni=\frac{n(n+1)}2$ in your textbook works for sets of the form $\{1, 2, 3, \dots, n\} $. The logic behind that function is that the terms can be paired when summing them all, so that there are $\frac n2$ pairs, whose sums each give $n+1$ (if $n$ is odd, the middle term equals $\frac {n+1}2$). The first and last terms give $1+n$; the second and second-last terms give $2+n-1=n+1$; and so on. 
