Originally Posted by Philip M
As this is plainly homework here is no point in offering the OP (this is his first post here) advanced/sophisticated solutions. Teacher may be dim, but not so dim as not to suspect external help!
Obviously the student can't hand in a real world solution to the problem in this type of situation since the real world solution uses commands that haven't been taught yet.
I disagree that there is no point in offering such solutions though.
1. The particular problem is one where there is a far better solution that the one the teacher expects so the particular question being asked is not one for which the code the teacher expects to be used in the answer would normally be used. (Why can't the teachers ask questions where the code being tested is appropriate to use for the solution?) So the student will know which way to go in trying to solve similar problems in the real world after they finish their course.
2. The person asking the question (and their fellow students) are not the only people who will ever be looking for solutions to that type of problem. By providing a real world solution those who are not students who have a similar problem they need to solve will see how to do it properly.
Admittedly none of those get the student closer to being able to provide the answer that their dim teacher expects and so it is also necessary to provide advice as to how they should go about fixing the code they ask about in the first place. With the knowledge that such a solution is a long way from being the best way to solve that particular problem and that their teacher did not present them with a problem where the code that they are supposed to know would be the appropriate way to solve it.