← All student tutorials

Tutorial 7 of 8

Complete a lab with the auto-grader

Later in the course the exercises get bigger. A lab asks for a whole function, worth 150 XP, checked by hidden tests that call your code and inspect what it gives back. A failed submission is a lesson, not a verdict.

  1. Step 1

    Read the whole brief first

    1. Open a lab, for example Implement count_all at /student/practice/lesson-counting-letters/coding-count-all.
    2. Read the narrative at the top. It states the rules: which characters count as keys, whether case matters, and how spaces and punctuation are treated.
    3. Read all four Instructions lines before typing. This is a whole function, not one line.
    4. The badge reads 150 XP and you get 3 hints left if you need them.
    The lab 'Implement count_all'. The left pane states the rules for the function and lists four instructions with a 150 XP badge. The right pane holds a function skeleton with blanks for the empty dictionary, the loop body, and the return value.
    A lab. Same in-browser Python as the short exercises, more of it, and the edge cases matter.

    Tip. The rules in the brief are the test cases. Anything the brief bothers to mention is something the hidden tests check.

  2. Step 2

    Submit, and read the failure

    1. Click Submit Answer when you have something to check, even if you are not sure it is right.
    2. A test report prints in a monospace block above the shell.
    3. A failure does not just say wrong. It names the input it tried and what your function actually gave back, for example FAIL: hidden tests -- banana: got {'b': 1, 'a': 1, 'n': 1}.
    4. Compare that against what the brief said should happen. In this case banana has three a characters, so a count of 1 means the loop is overwriting instead of adding.
    5. Change one thing and submit again. You can also click Run Code as many times as you like in between, for free.
    A failed lab submission. The editor sets counts[c] = 1 inside the loop. The shell header shows a red 'error — see output' badge and the report reads FAIL: hidden tests -- banana: got {'b': 1, 'a': 1, 'n': 1}.
    A failed submission names the input and what your code returned. That is the most useful thing on the page.
  3. Step 3

    Fix it and finish the module

    1. Make the change the report points at. For a counter, that usually means adding to the count instead of overwriting it.
    2. Click Submit Answer again. On a pass the shell reads PASS: hidden tests and prints your result.
    3. The badge flips to +150 XP earned and a toast confirms it.
    4. If this was the last step, the toast reads You finished every step in this module with a Finish button.
    The lab passing. The editor shows the finished count_all function using counts.get(c, 0) + 1. The shell reads 'PASS: hidden tests' with output {'b': 1, 'a': 3, 'n': 2}, the badge reads '+150 XP earned', and a toast reads '+150 XP — nice work! You finished every step in this module' with a Finish button.
    The finished function clears every hidden assertion, including the empty string and the mixed-case cases you never see.

    Tip. Hidden tests always include the boring cases: the empty input, the repeated character, the string with punctuation in it. Try those yourself with Run Code before you submit.