It is possible to earn an A without doing any extra credit . Different rules apply to extra-credit problems on examinations, if any. A solution to a problem is of little value if that solution cannot be understood and modified by others. For that reason, your homework will be graded on your explanation of what you are doing as well as your results. For many homeworks, especially those involving substantial programming, half of your grade will be based on your explanation.
Appropriate explanations vary with the size of the problem.
For a trivial solution of a few lines of code, it may be best to have no explanation at all. For a solution of a dozen lines of code, a sentence or two is usually sufficient. For these kinds of small problems, the best method of explanation is comments in with the source code itself. For a solution of a hundred lines or more, I would expect several paragraphs of explanation. Here the explanation needs to cover not so much the code itself, but the organization of the code and the plan that produced it.