Score: 48/50

score

Corrections

Q41: Procedure most useful in replacing negative values

A student is writing a program that is intended to replace each negative value in a particular column of a spreadsheet with the value 0. Which of the following procedures is most likely to be useful in the student’s program?
  • Original answer:
    • A procedure containsNegatives, which returns true if any negative values appear in the column and returns false otherwise.
  • Correct answer:
    • A procedure findNegative, which returns the row number of the first negative value that appears in the column or -1 if there are no negative values.
  • Explanation
    • Being able to identify if there is a negative and where it is is most beneficial for the intended purpose. The original is incorrect because it returns true for a whole list but doesn't tell you where.

Q28: Remove first and last two characters of string

A teacher stores the most recent quiz scores for her class in the list scores. The first element in the list holds the maximum possible number of points that can be awarded on the quiz, and each remaining element holds one student’s quiz score. Assume that scores contains at least two elements. Which of the following code segments will set the variable found to true if at least one student scored the maximum possible number of points on the quiz and will set found to false otherwise?
  • Original answer:
  • Correct answer:
  • Explanation
    • Original answer is wrong because it won't check the very last item in the list. Correct is right because it successfully does check all items.