CS FundamentalsVery hardProduct-company placement

What is the cyclomatic complexity of this function, counting each simple condition separately and each loop header as one decision?

What is the cyclomatic complexity of this function, counting each simple condition separately and each loop header as one decision?
def classify(nums):
    pos = neg = 0
    i = 0
    while i < len(nums):
        n = nums[i]
        if n > 0 and n % 2 == 0 or n > 100:
            pos += 1
        elif n < 0:
            neg += 1
        i += 1
    return pos, neg
  1. A. 4
  2. B. 3
  3. C. 6
  4. D. 1

Correct answer: C. 6

Decisions: while (1), the compound condition with three simple conditions (3) and elif n < 0 (1) = 5, so V(G) = 6. Counting the compound condition once gives 4, counting the three statements without the + 1 gives 3, and 1 treats the function as a single path.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic