For students
When your program does not work
Programs not working is most of learning to program. The useful skill is not avoiding it. It is narrowing down where the problem actually is.
Read what it actually says
When a program fails, the output tells you what went wrong and usually which line. That message is worth reading properly before changing anything, because the error you have is often not the error you assumed.
A program that runs but gives the wrong answer is a different problem. Nothing is broken, so nothing will tell you. You have to compare what it produced with what it should have produced.
Try it with different input
If it works on the example and fails on something else, the input is where the answer is. Run it again with the empty case, a single item, and something larger than you expected to handle.
That is also how your work gets marked if you are set an assessment: programs are checked by running them against inputs somebody else chose.
Watch it run, line by line
Some programs run without any error and still give the wrong answer. There is nothing to read in that case, because nothing went wrong as far as the computer is concerned.
For those, stop the program in the middle and look at it. Click a line number to set a breakpoint, press Debug instead of Execute, and the program stops on that line. You can then go one line at a time and watch your variables change, which usually shows you the exact step where the value stopped being what you expected.
This works for most languages. See the debugger.
Ask the assistant
The AI assistant is in the editor and knows what you have written. Asking it why an error is happening, or what a message means, is usually faster than searching for the message on its own.
Ask it to explain rather than to fix, when what you want is to be able to do it yourself next time.
What next
If a teacher has asked you to join their account, that is where the work they set starts arriving.
The AI assistant can also explain an error message you do not recognise.