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- A. 3
- B. 5
- C. 2
- 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.
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
- How many of the following are white-box (structural) testing techniques? 1. Branch (decision) coverage 2. Basis path testing 3. Boundary…
- You cherry-pick commit X from branch feature onto main. Which statement is correct?
- git push origin main is rejected with a 'non-fast-forward' error. What does it mean, and what is the correct fix on a shared branch?
- Which document records what a system must do — its functional and non-functional requirements — as agreed with the client before design…
- Before a sale, a team checks that its shopping site still responds well with 10,000 concurrent users, the expected peak. Which type of…
- Which of the following is a NON-functional requirement for an online banking app?