So I solved this assignment and got the same answer as the person in this thread. The answer is correct and I also verified it by plotting with software. The answers are
$$f(x)=\frac{\pi^2}{3}+4\sum_{n\in\mathbb{N}}\frac{(-1)^n}{n^2}\cos(nx),$$
where $a_0=2\pi^2/3$ and
$$a_n=\frac{4(-1)^n}{n^2}.$$
However, If I want $a_0$ fron $a_n$, by calculating $a_n$ for $n=0$ I get a division by zero. I found that this only works sometimes and not always. Why is this and when does it work and not work?
Also, If the assignment asks me to "compute the Fourier series of..." How do I know wheather I should go the complex Fourier series or real?