I am often asked for sample answers to assignments and tests. Quite often I say no. Let me explain why.
If your answer to this question is "To get a degree", then I suggest you just send a cheque to an overseas mail-order degree company. They'll send you a lovely certificate you can frame and hang on your wall, and you won't be wasting three years of your time and mine.
The problem with mail-order degrees, of course, is that they're worthless. Actually there is no inherent value in any degree -- the value is in the education that the degree testifies you've acquired. So, like it or not, you're actually at university to get an education.
This is not as frivolous an issue as you may think. Many students seem to have genuinely lost sight of the fact that they're here for an education. They are single-mindedly focused on passing examinations. They want lots and lots of worked examples, together with sample answers to assignments and final exams, and they mindlessly learn the answers to these problems. At very best they might learn how to solve some particular type of exam question, but the problems you meet in exams are rarely of any relevance to real life. Once you've left University, an ability to pass exams is about as useful as a mail-order degree.
Suppose instead that you don't know how to answer the question and I don't give you the sample answer. Now you have a problem. You have to start thinking. You have to get your lecture notes out, and try to figure out which bits might be relevant. You actually start to learn something. And yet, many students seem to regard this process as an irritating waste of their time, a consequence of a nasty mean lecturer who won't provide sample answers!
So I'm sorry, but if you've come to University with the objective of learning to pass exams and little else, then I aim to be as unhelpful as I can be. Because I believe I am here to help you acquire an education.
Having said all that, I'm not totally opposed to making some sample answers available. The process of putting a tick by your right answer is actually useful and encouraging feedback, I admit. So in many courses I try to make some answers available to a subset of exam and test questions. But I don't do that in programming-type courses where you should usually be able to verify answers by typing code into a computer. In programming courses there simply isn't a right answer -- there's an infinity of right answers and my answer would probably look very different from your right answer (or from your wrong answer!).
Assignments are a vital part of the learning process. Indeed, I'm often heard to claim that nearly all the learning takes place in assignments. This is particularly true of programming assignments. You can read code and think you understand it, but as soon as you're faced with solving a problem of your own, you suddenly discover how little you actually know! That's when the real learning starts: you grapple with the problem, re-read the documentation, experiment with ideas, and so on.
When you've finished the assignment and handed it in, most of the learning has taken place. A bit of feedback from the markers may help, of course, although often it just tells you what you already knew. But you're still left wondering whether there was a better way of solving the problem, and that's when you ask for a sample answer, right? Fair enough -- you're right that having a sample answer at this stage can potentially improve the learning experience. To that extent, I'm sympathetic to your requests, and I often hand out sample answers at stage 1 or discuss them in class. But there's another side to the story, which students often don't see. The reasons I don't like handing out sample answers to assignments are:
This might not seem important to you, but preparing a good assignment at higher levels often involves a huge amount of work, and preparing completely new assignments each year is just too expensive. I often try to get around this by modifying the assignment somewhat, but results are often unsatisfactory. It's very depressing to see students who have got hold of the solution from the previous year mindlessly hacking at it, trying to get it to conform to the new spec.
So it comes down to a tradeoff: do I feel that the relatively small learning benefit obtained by some students from handing out a sample answer is sufficient to offset the negative effects on my time and/or the learning of future students? Often the answer is no. Sorry.
Please remember: the REAL learning takes place while you do the assignment. The actual answer you come up with is not the important thing. Where assignments are concerned, it's almost true that: "It's not whether you win or lose that's important. It's how you play the game!"