results.append(getaverage(student))

is what I wrote but the lesson told me to use

student_avg = get_average(student)

results.append(student_avg)

I would like to understand why this has to be split up like that and can’t be nested in one line.

results.append(getaverage(student))

is what I wrote but the lesson told me to use

student_avg = get_average(student)

results.append(student_avg)

I would like to understand why this has to be split up like that and can’t be nested in one line.

I had a math teacher once who insisted we do things his way and would give low marks to anybody who did not. Needless, I kept looking for simpler, more elegant ways to do things and got a lot of low marks for bucking what he asked. Moral of the story… Just because we think we are right, does not make it so.

Following instructions is how to get the teacher to mark you as right. This author wants to see that we understand how all the pieces fit together and gives no marks for initiative. If the lesson expects something to be a certain way, then humor the author and give what is expected. There will be plenty of time to prove one’s own mettle in due course of time. During a course is not that time.

So what you’re saying is that my answer is correct but not THE correct answer that was anticipated?

Correct. Learning often comes with few shortcuts at first, so that we get an idea of the complete picture before abstracting away the superfluous bits. Your code is perfectly valid, only it takes a shortcut that may not have been called for, yet.

Later on you will learn more about optimization, but this is not the time to concern one’s self with that. Draw everything out into the open and see how the pieces fit together as individual parts.

Take for example maths. We can look at a long, drawn out expression that if we calculate straight from that will give us the answer. However, there may be several steps involved and lots of secondary calculations that can lead to small errors. That is why our teachers are so insistent upon us learning how to simplify equations before reaching for the calculator.

Often, by the time we get to the simplest form, we can work out the answer in our head, or with only one or two simple calculator steps. This is how we reduce computation errors to a minimum, even zero.

Code optimization is much the same thing. But, we should first create something that works, then work toward simplifying it by reducing code bloat and verbosity. Don’t expect your first crack at something from scratch to be the elegant code you will end up with. Take the time while learning to absorb all the drawn out approaches so you will see the pieces fit together.

Thank you for your answer. I don’t mind learning the long way before finding the shortcuts. I suppose there’s no way for the course to explain that my answer works but there’s another way of doing things so instead it just says it’s wrong.

What would result is TL; DR that might confuse more than elucidate. We run the risk of excluding far more learners than we help when instructions become too complex or try to account for too many outcomes. I would suspect there will be no further modification of the lesson instructions so it is what it is. At least now you know that keeping to the straight and narrow is the way to succeed in these courses.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.