CS FundamentalsHardProduct-company MCQ pattern
What is the cyclomatic complexity of this function?
What is the cyclomatic complexity of this function?
def grade(m):
if m >= 90:
return "A"
elif m >= 75:
return "B"
elif m >= 50:
return "C"
return "F"- A. 3
- B. 4
- C. 1
- D. 5
Correct answer: B. 4
Three decision points (the if and two elifs) plus one: 3 + 1 = 4. Equivalently there are 4 independent paths, one per return. The final 'return F' is not a decision.
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 developer runs git reset --soft HEAD~1 on a branch. What happens?
- A bad commit has already been pushed to a shared main branch that teammates have pulled. What is the safest way to undo it?
- When does git merge feature (run on main) produce a fast-forward instead of a merge commit?
- A stock-price service must notify every registered display widget whenever the price changes, without knowing the widgets' concrete…
- Your application expects a PaymentGateway interface, but the third-party library you must use exposes a different API. Which pattern lets…
- class Square extends Rectangle overrides setWidth() so that it also changes the height. Code that sets width = 5 and height = 4 on a…