—
Trace a sentinel-based string scan
Tutor me on https://mlprep.iwase.dev/item/prog-cf-trace-sentinel/. This is a screening item. If window.mlPrepAgent is available, read attempts for item prog-cf-trace-sentinel before tutoring. Inspect my attempt, keep the item ID, and do not reveal the full answer first. After a real attempt, append its record with recorded_by agent, include agent_session_id when available, and read it back.Problem
Without running the code, determine scan_until_marker(" A1-b 2#C9").
The scan stops at the first #, ignores whitespace, adds digit values,
lowercases letters, and records ? for every other character.
Reveal answer or reference solution
The result is ("a?b", 3). The leading space and the space before 2
are ignored. A and b contribute a and b; - contributes ?;
; and no character after # is visited.
def scan_until_marker(text: str) -> tuple[str, int]:
letters: list[str] = []
digit_sum = 0
for character in text:
if character == "#":
break
if character.isspace():
continue
if character.isdigit():
digit_sum += int(character)
elif character.isalpha():
letters.append(character.lower())
else:
letters.append("?")
return "".join(letters), digit_sumPublic tests
scan_until_marker(" A1-b 2#C9")→('a?b', 3)scan_until_marker("")→('', 0)scan_until_marker("X7 Y3")→('xy', 10)scan_until_marker("9#8")→('', 9)
Previous attempts
Loading attempts saved in this browser…