CS FundamentalsVery hardIBM · Deloitte pattern

Counting each simple condition in a compound boolean expression as a separate decision, what is the cyclomatic complexity of this function?

Counting each simple condition in a compound boolean expression as a separate decision, what is the cyclomatic complexity of this function?
def grade(score, attendance):
    if score >= 90 or attendance < 50:
        if score >= 90:
            return "A"
        return "F"
    elif score >= 60:
        return "B"
    return "C"
  1. A. 6
  2. B. 3
  3. C. 5
  4. D. 4

Correct answer: C. 5

Counting decision points: 4 (each if/elif/while/for test, and each 'and'/'or' as a separate condition). Cyclomatic complexity = decisions + 1 = 4 + 1 = 5.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic