Trimester 1 Final

I scored 48/50. The questions I missed were Q11 and Q13.

Q11

How nested loops with lists function

My answer: A) The code segment iterates through myList, comparing each element to all other elements in the list. Answer: B) The code segment iterates through myList, comparing each element to all subsequent elements in the list.

I could tell that there is iteration, but I didn’t consider that it would need to be in subsequent order. To be truly honest, I didn’t know what subsequent meant, so I didn’t consider this factor. The algorithm traverses myList using two nested loops. The outer loop iterates from the first element in the list to the second-to-last element in the list. For each iteration of the outer loop, the inner loop compares that element to every subsequent element in the array.

Q13

Test cases for allPositive in a list

My answer: B) [-2, -1, 0] Answer: C) [-1, 0, 1]

I got confused with the 0 in the answer; 0 is not a positive number. The procedure traverses this list and eventually encounters the positive value 1. At this point, the procedure returns true when it should return false because the list does not contain only positive values.