There is sometimes an extremely fine line between "helping" (which is good) and "spoonfeeding" (which in the long term isn't).
As much as possible, its about getting the poster to think for themselves a bit - which for newbies can be an extremely frustrating experience as it often seems like people are not really helping. But a large part of programming is down to thinking about the problem, and it's only when you "get" that aspect of it that you can start to tackle the really interesting programming problems.
So I try and restrict code to smaller snippets which nudge posters past the more immediate problem just so they have the "making progress" feeling, and don't feel like they're completely stuck and give up altogether. Those that do give up too soon would never make it anyway, so there's no loss there.
When I do post a whole answer, it's as an example after the fact rather than as an up-front answer to the question.
The other thing to do is respond with equal effort.
If the OP has basically dumped the assignment, then that gets the short flame or just ignored.
A post containing code and questions gets far more attention.