You are given a coin with probability $\frac23$ to land on heads and $\frac13$ to land on tails. If you flip this coin until you get a tails immediately followed by heads, how many times do you expect to flip the coin?
We can say the E(TH) sequence is $\frac23$(Expectation | first flip is heads) + $\frac13$(Expectation | first flip is tails). If first flip is heads, no progress was made so (Expectation | first flip is heads) = E(TH + 1). If first flip was tails, we flip until we get a heads. This is geometric with $p=\frac23$ so we can expect an additional $\frac32$ more flips. Thus we get:
$E(TH) = \frac23(E(TH) + 1) + \frac13(\frac32 + 1) \rightarrow E(TH) = 4.5$
However, when I script this, I am getting 6 expected flips. Is there a flaw in the math or the script?

Your maths is correct.
Alternatively: we will flip until we obtain the first tail, and then we flip until we obtain a head.
$\begin{align}E(TH) &= E(\text{flips until first tail})+E(\text{flips until first head}) \\ &= 3/1 + 3/2 \\ &= 9/2\end{align}$