Python: How we check your solutions
Our site automatically checks your solutions. Here is how it works.
In the simplest case, the system runs your code and looks at what appears on the screen, then compares it to what the task expected. For example, if the task is "display the number 10", your code might look like this:
print(10)The system runs it and checks that 10 actually appears on the screen. If it matches — the solution is accepted. If not, you'll see an error:
E AssertionError: assert '9' == '10'
E
E - 10
E + 9The line with - shows the value the test expected. The line with + shows what your code actually produced.
In later, more complex lessons, you will write functions — mini-programs that take input from the outside world and perform operations. Checking those solutions works a bit differently: the system calls your function with different inputs and compares the results against the correct answers. If all the answers match, the solution is accepted.
This approach is called testing, and it's used in real everyday development. Typically, a developer writes a test first — a checking program — and then writes the actual program. Along the way, they constantly run the tests to see how close they are to a working solution. That's why the site says "Tests passed" when you solve a problem correctly.
My fault or not?
Sometimes it may seem like you've done everything right, but the system keeps rejecting the solution. In practice, this almost never happens because of a bug in the tests — tests are automatically run after every change and can't reach the site if they're broken. In the vast majority of cases, the mistake is in the solution code. It can be very subtle: a Russian letter typed instead of an English one, wrong letter case, a missing comma. Other cases are trickier — your solution might work for one set of inputs but fail for another.
Always read the task description and the test output carefully. There is almost always a clue pointing to the error.
If you're convinced there's a mistake in the task itself, you can report it. This project is open source on GitHub, so you can open an issue, read the test code to see how your solution is called, or even send a pull request.
Instructions
Display 10.
Tips
If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:
- Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
Tests are designed so that they test the solution in different ways and against different data. Often the solution works with one kind of input data but doesn't work with others. Check the «Tests» tab to figure this out, you can find hints at the error output.
It's fine. 🙆 One task in programming can be solved in many different ways. If your code passed all tests, it complies with the task conditions.
In some rare cases, the solution may be adjusted to the tests, but this can be seen immediately.
It's hard to make educational materials that will suit everyone. We do our best but there is always something to improve. If you see a material that is not clear to you, describe the problem in “Discussions”. It will be great if you'll write unclear points in the question form. Usually, we need a few days for corrections.
By the way, you can participate in courses improvement. There is a link below to the lessons course code which you can edit right in your browser.
Your exercise will be checked with these tests:
import runpy
def test(capsys):
expected = "10"
runpy.run_module('solution')
out, _ = capsys.readouterr()
assert out.strip() == expectedTeacher's solution will be available in:
20:00
