Does there exist an unfair coin such that the probability of an even number of heads in $n$ flips is $\frac{1}{2}$?

Consider the random variable in which the value of a flip sequence is $1$ if the number of heads is even and $-1$ if the number of flips is odd.

Its expected value is $\sum\limits_{i=0}^n \binom{n}{i}(-1)^ip^i(1-p)^{n-i} = ((-p) + (1-p))^n = (1-2p)^n$.

We need this expected value to be $0$, this happens only when $p$ is $\frac{1}{2}$.


With the probability of heads being $p$ and $n$ tosses the probability of getting an even number of heads is $$\sum_{k=0}^{\lfloor n/2\rfloor}\binom n{2k}p^{2k}(1-2p)^{n-2k}=\frac12+\frac{(1-2p)^n}2$$ which is $\frac12$ iff $\frac{(1-2p)^n}2=0$ iff $1-2p=0$ iff $p=\frac12$. Hence if the probability of tossing an even number of heads is exactly $\frac12$, the coin is fair.