Quiz 6 Feedback
Here are some general statistics and feedback for your Quiz 6:
The overall mean was 11.9/22. Q1: 3.6/5; Q2: 4.1/7; Q3: 4.1/10
Question 1
This question was designed to test your grasp of syntax and concepts, which is the required criteria for getting a "C" in COMP 201.
There are three mistakes in this program:
- Three programming statements were not indented when they should be; almost everybody got that correct.
- The print() statement in the last line of main() should not be part of the for loop
- The variable i (the loop index) is a character in the string. Since i is a character, i+1 is the next character after it in the alphabet, not the next character in the string. Therefore, the mistake is in the ord(i+1) statement.
Most of you got the indentation error, which is good. If you didn't catch that error, you really need to start being worried about your grasp of the concepts. The ord(i+1) error is harder, but just trying out that loop in the Python interactive shell and printing out the values of i and i+1 should have shown you what was wrong. You need to start trying things out on your own, there's only so much that we can teach you in class!
Question 2
This question mainly tests your grasp of concepts, specifically, the concepts of references that we went over last week. What you need to do here is to make a new list in the squareList() function, and then return the reference of that list to main()
Added on Nov 2 2009: The concepts tested in this question are:
- Sequentiality. Are you able to grasp the concept that programming statements are executed in order? You need to grasp that in order to realize that the squareList() function created a new list.
- Function parameters, especially as pertains to reference values.
- Lists indexes and multiplication/addition
- Return values in functions
Some of the wrong solutions are here:
def squareList(list):
for i in list:
i = i**2
return list
Two errors here:
- Again, the variable i is an item in the list, not a position in the list. What you're doing here is just updating the value of the variable i, not the item in the list.
- Remember that the variable list in the function refers to the same list from main(). Therefore, there's no point in returning the reference to this list. But it seems that there are two lists in main(), you say. Well, that's why we need to make a new list, and return the reference to it!
def squareList(list1):
for i in list1:
list1[i] = list1[i]*list1[i]
return list1
Two problems here:
- Same problem that we've been seeing: list1[i] means "the item in position i of list1", not "the position of element i in list1".
- The return keyword terminates the function. In this case, as soon as the first iteration sees the return, the function will be terminated. The rest of the loop will not get executed.
Question 3
Question 3 is not that hard when it comes to the logic, but we were surprised that a lot of you had trouble with it. From what we can tell, it seems that most people spent too much time on Questions 1 and 2, and didn't have enough time for this question.
Other common mistakes
- Some of you wrote stuff like if a = 2 -- remember that = is the assignment operator, not the equality operator!
- Many students lost 1 mark because of carelessness (very few of you got full marks this time around). Remember that when we give you sample output, that's the exact output that we need. Some common mistakes are:
- Q2: Forgetting the brackets [..] for the indexes
- Q2: Printing out [1, 9, 25, 49, 81] as the old list
- Q3: Printing out excess commas, such as 1, 3, 5, 7, 11,, or ,1, 3, 5, 7, 11
- Forgetting to comment out your debug messages before handing in!
That's it. We hope that by providing this feedback, it will help you to avoid making the same mistakes next time. Hope that this is useful.