SECTION 15 / 17

Tutorial: one combined count or two separate counts?

1 min read
The word cards have one PartOfSpeech label per occurrence. There are 21 noun cards and 7 verb cards: 28 cards in their union.
The word cards have one PartOfSpeech label per occurrence. There are 21 noun cards and 7 verb cards: 28 cards in their union.
REAL COURSE DATA · THINK BEFORE EACH STEP

Count nouns and verbs separately

Trace the records, compare the methods and watch what changes. Back and Reset let you try again.

Ready

CURRENT RECORD X

Ready to begin

Choose Next step to follow the actual course records.

What we remember

Processed
0

Start with Next step. Predict what changes before reading the explanation.

In these tagged word cards, an occurrence has one PartOfSpeech value, so Noun and Verb are mutually exclusive labels. Counting Noun OR Verb gives 28. Two separate IF statements that both increase the SAME Count also give 28 here because a card cannot pass both tests.

Ncount = 0
Vcount = 0
for each word card X:
    if X.PartOfSpeech == "Noun":
        Ncount = Ncount + 1
    if X.PartOfSpeech == "Verb":
        Vcount = Vcount + 1
# Ncount = 21, Vcount = 7

Now consider the wrong rewrite: IF Noun OR Verb, increase Ncount AND increase Vcount. Every noun then increases the verb counter, and every verb increases the noun counter. Both counters become 28. Keeping two counters means the updates must remain connected to the correct conditions.

These counts are word-card occurrences, not distinct spellings. A word may appear several times in the paragraph. In general English a spelling can have different grammatical roles in different sentences; our exclusivity claim is about the single label stored on each particular card.

Try it yourself

Can Ncount = 28 and Vcount = 28 be the correct separate counts for these cards?

Show explained answer

No. Those are the results of the incorrect combined-update block. Correct separate counts are 21 and 7.

Try it yourself

Does “Noun OR Verb” require a card to be both?

Show explained answer

No. Either label is enough. Requiring both would be AND, which no single label in this dataset satisfies.

Try it yourself

Why does the separate-IF rewrite work for one combined count here but fail for Maths > 90 OR Physics > 90?

Show explained answer

The noun/verb labels are mutually exclusive on a card. A student can pass both subject thresholds, creating overlap.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑