Intermediate
Parse and check citations
Write citations(text) returning the list of integers found as [n] in the text, in order (repeats included). Brackets that do not hold only digits, like [x], are ignored.
Write check_reply(reply, n_sources) returning one string: "refusal" if the stripped reply equals REFUSAL; "no citation" if it has no citation; "bad citation N" for the first cited number N that is below 1 or above n_sources; otherwise "ok".
What Check tests
citationsfinds numbers in order, repeats included- Brackets without a number are ignored, and two digits work
- The refusal sentence gives
"refusal" - No citation gives
"no citation" - A source number out of range gives
"bad citation N" - Valid citations give
"ok"
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.