CS FundamentalsVery hardProduct-company MCQ pattern

What is the cyclomatic complexity of this function, counting the conditional expression and the except clause as decisions?

What is the cyclomatic complexity of this function, counting the conditional expression and the except clause as decisions?
def parse(rows):
    total = 0
    for r in rows:
        try:
            v = int(r)
        except ValueError:
            continue
        total += v if v > 0 else 0
    return total
  1. A. 3
  2. B. 5
  3. C. 2
  4. D. 4

Correct answer: D. 4

Decisions: for (1), except ValueError (1), the conditional expression v if v > 0 else 0 (1) → 3, plus 1 = 4. The try itself is not a decision; missing the inline conditional gives 3.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic