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"- A. 6
- B. 3
- C. 5
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A system has these unadjusted function-point counts (standard average complexity weights: EI=4, EO=5, EQ=4, ILF=10, EIF=7): External…
- A system has these unadjusted function-point counts (standard average complexity weights: EI=4, EO=5, EQ=4, ILF=10, EIF=7): External…
- A system has these unadjusted function-point counts (standard average complexity weights: EI=4, EO=5, EQ=4, ILF=10, EIF=7): External…
- A system has these unadjusted function-point counts (standard average complexity weights: EI=4, EO=5, EQ=4, ILF=10, EIF=7): External…
- A system has these unadjusted function-point counts (standard average complexity weights: EI=4, EO=5, EQ=4, ILF=10, EIF=7): External…
- A system has these unadjusted function-point counts (standard average complexity weights: EI=4, EO=5, EQ=4, ILF=10, EIF=7): External…