Reproduce before you fix
Do not change code until you can re-run the failing case on command. A test is that case. Once you can make it go red on demand, you have a loop: change something, re-run, see if it went green. Guessing without that loop is how people break a second bug while fixing a first.
Bisect by printing
When you do not know where a value goes wrong, put prints at a few points and read them. The last correct print and the first wrong one bracket the bug. Move the seam inward until the bracket is one line. That one line is the fix.