Now this is a trick question:
What is the value of x after this code executes:
int age = 21;
int x = 15;
if (age >= 21)
x = 15;
age = age + 1;
x = age;
It’s a trick question, in my opinion anyway, because it uses tabs to make it look like three statements are executed if the if statement is true. And that may be the case in some languages but in C-family languages like C, C++. Java, and in my case C# it’s not. I want students to realize that without curly braces x is going to be 22 no matter what else goes on. There is some extra code in there just to confuse things. Is that a good question? Arguably not but students never complain about it. What to they stress over and question me on? The freebee question I tossed in to make the quiz an even number of questions.
Enter the letter A as the answer to this question
I want more questions that require students to read code. The thing I struggle with is how to write good code reading questions without using poor coding practice. The AP CS A test has some and I toy with borrowing some of them and making adjustments for various programming languages but so far I spend more of my time trying to come up with projects.
I’ve also used Code Hunt with some classes with mixed results. I may tackle that again soon. It can be tricky to set up your own questions though.
I have been reading about questions that ask students to put lines of code into the correct sequence. (Parson's Problems) That seems like a good idea. I wish I had a good tool for both writing them and having students work them out online. Any one know of such? (Looking at one in the comments.)
What sorts of questions do you ask programming students? What tools do you use to ask coding questions?
2 comments:
I like your missing curly bracket question, but I'd use it as an ungraded practice question since it's more of a learning opportunity than a test of student knowledge. I'd assume 99% of my intro students would get that question wrong, and even a majority of my APCS students. It's an important concept, though, since it's a common error I see in my classes.
Look here for a Javascript library for creating Parson's Problems:
https://js-parsons.github.io/
Post a Comment