Skip to content

cs50/problems/2022/python/um: check50 accepts substring-based solution that counts words like "umbrella" as "um" #387

@kali-mx

Description

@kali-mx

Summary

Raising this to help improve the autograder tests for future students.

For cs50/problems/2022/python/um, check50 currently accepts a count implementation that treats "um" as a prefix/substring rather than a whole word. As a result, count("umbrella") returns 1, but check50 cs50/problems/2022/python/um still passes.

This appears to contradict the spec, which states that "um" should be counted only "as a word unto itself, not as a substring of some other word."


Minimal example

Here is a (deliberately incorrect) implementation of count:

def count(s):
    tally = 0
    pieces = s.split(" ")
    for item in pieces:
        if item.lower().startswith("umm"):
            continue
        if item.lower().startswith("um"):
            tally += 1
    return tally

With this implementation:

>>> count("um")
1
>>> count("Um, thanks, um...")
2
>>> count("umbrella")
1        # <-- incorrect per spec, but not caught by check50

Despite this clearly incorrect behavior for "umbrella" (and other words like "umlaut" or "umami"), check50 cs50/problems/2022/python/um reports all tests passing.

Expected vs actual behavior

Expected: check50 should fail implementations that count "um" inside larger words, per the problem specification.

Actual: A substring-/prefix-based implementation like the one above passes all check50 tests.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions