CS FundamentalsVery hardProduct-company MCQ 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 tally(a, b, items):
count = 0
for x in items:
if x > a and x < b:
count += 1
elif x == 0 or x == -1:
continue
while count > 10:
count -= 10
return count- A. 6
- B. 5
- C. 7
- D. 4
Correct answer: C. 7
Decisions: for (1), x > a and x < b (2), x == 0 or x == -1 (2), while (1) → 6, plus 1 = 7. Treating each compound condition as a single decision gives 5, the trap answer.
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 program's control flow graph has two separate connected components (for example, main and one called function drawn separately), with 14…
- How many of the following statements about cyclomatic complexity are correct? 1. It equals the number of linearly independent paths…
- A function has three integer inputs. How many test cases does worst-case boundary value analysis (every combination of min, min+, nom…
- main has commits A–B–C. Branch feature was created from B and has commits D–E. On feature you run git rebase main. How many of these…
- How many of the following statements about git reset are correct? 1. git reset --mixed HEAD~1 removes the last commit and leaves its…
- On main you run git merge --squash feature and then git commit. Afterwards you try git branch -d feature. What happens?