top of page
Search

Assessment part 2

  • Writer: gregbeutler
    gregbeutler
  • Jul 26, 2022
  • 3 min read

So before I begin, let's compare notes, take a look at this student's submission below and write down what comes to mind.


What errors do you see? What feedback do you have for this student? and if you're jumping in, make sure you see the last Blog post, on Assessments, so you can understand the problem. It's to have the student build a calculator, only addition of 2 digit numbers, but instead of calculating numbers, it checks the answers and if correct asks up to 9 more addition questions, and if incorrect prints "EEE" and allows 2 more answers and if all are incorrect, prints out the correct answer and continues on for the remainder of the 10 problems.




Hopefully you've taken the time to review this and have a few comments.



  • lines 9 and 10 and 11 , bad variable names X and Y and q, but not uncommon for new coders.

  • line 18, good use of break keyword, as there doesn't need to be 3 tries, as the answer is correct

  • redundant code 16-17 and 22-23. Again, a new coder who is rushing.

  • line 7 good variable name "Score" but we don't need the score at the very beginning, a) we know the score has to be 0, nothing has happened yet and redundant, as it's also printed out on line 28.

  • line 22 is curious- again, why is it the same as line 16 ?

Otherwise readable and fairly clean, 1 If/else pair it doesn't nest further or go on and on. ( lines 16 and 19)


So, in a subsequent class, I would take this student's code and hand it out to the class to have them a) identify areas of concern and comment and have a class discussion of what constitutes good coding. And guide that discussion, hopefully they will surface similar bullet points to those I've listed.


I would ask if this was a) satisfactory and b) where improvements could be made. Usually, I have them start deleting things until they understand what is going on and add code line by line, function by function, testing all the while to make sure they haven't broken anything and that the code the have added does what they think it should be doing.


and I'd be sure to ask why the comparison code in line 16 ( or line 5 below) is written that way. What are we trying to do? Aren't we trying to compare the users input ( a number) to the sum of X + Y?




And what happens if a few weeks later you revisit the code and make the changes to X and Y like in line 8? What then? Which makes more sense?


Hopefully they see how it can get confusing and what really needs to happen is that input1 needs to a) be checked if it's numerical and b) cast as an integer before being used in the if statement, so its a number compared to a sum




Which the above code shows better in line 7. We are comparing an int to a sum of X and Y, which are both ints.


That's a clearer expression of what this code *SHOULD* be doing. Comparing numbers instead of comparing strings, as it is a calculator addition program


This also shows how the cast in line 3 of the string "5" converts it to a numerical 5 and assigns it to input1.


lastly, the student's code has 0 comments. That's a problem. Anyone coming to this would have to re-read the original problem to begin to understand what is going on.



and finally I'd share my code for this and ask them what they saw and if they thought it was better.

my code snippet is below




As you can see, I'm checking to see that the user entered a numerical value on line 24, then converting it to an integer type on line 25

and then finally doing an integer to integer comparison on line 26 in the IF comparison.


and you can see my else case is pretty clean, Just print out the error message 'EEE" if the integer math fails and print out 'EEE' if the user_answer is not a number.



---end of blog---

 
 
 

Commenti


bottom of page