Python: How we check your solutions
Our site automatically checks your decisions. How does it work?
In the simplest case, the system just runs your code and looks at what's on the screen. And then it checks against what we "expected" from the job.
In the next, more complicated lessons, you will write functions, mini-programs that take information from the outside world and perform some operations. Checking your decisions in such cases looks a little more complicated: the system runs your decision and sends some information. The system also knows - "expects" - exactly what answer the correct function should give with this input.
For example, if your task is to write a function for adding two numbers, then the checking system will pass it different combinations of numbers and check the answer of your function against the real sums. If in all cases the answers are the same, then the solution is considered correct.
This approach is called testing, and it is used in real everyday development. Usually the programmer first writes a test, a test program, and then the program he wants to write. In the process, he is constantly running tests and seeing if he has come close to a solution.
That's why our site says "Tests passed" when you solve the problem correctly.
Here is a simple example: in a future lesson, you will need to write a function that performs calculations and gives the answer. Suppose you make a small mistake and the function gives you the wrong number. The system will answer something like this:
AssertionError: '10' != '35'
The most important thing begins after the colon: "the value of '10' is not equal to the expected value of '35'". That is, the correct function should have produced 35, but the current solution does not work correctly and produces 10.
It is also worth noting that if you see that there is already some code in the editor, and along with it the comments BEGIN
and END
, it usually means that you have to write your code between these very BEGIN and END! The code given to you beforehand should not be touched: it may affect the validation of the solution. To put it simply: you see lines with comments BEGIN
and END
— write your code between them!
Sometimes it will seem that you have done everything correctly, but the system is "capricious" and does not make a decision. Such behavior is practically excluded. Non-working tests simply can not get to the site, they automatically run after each change. In the vast majority of such cases, (and all of our projects have done millions of tests in total over many years), the error is contained in the solution code. It can be very subtle, instead of English letters accidentally entered the Russian, instead of upper case used lower case or forgot to display the comma. Other cases are more complicated. Your solution may work for one set of input data, but not for another. So always read the problem statement and test output carefully. There is almost certainly an error indication there.
However, if you are sure of an error or find some inaccuracy, you can always point it out. At the end of each theory, there is a link to the contents of the lesson on the githab (this project is completely open source!). By going there you can write an issue, look at the contents of the tests (you can see how your code is called) and even send a pullrequest. If this is still a dark forest for you, join our Slack community, #hexlet-feedback we are always there for you.
Instructions
Display 9780262531962
.
The exercise doesn't pass checking. What to do? 😶
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.
In my environment the code works, but not here 🤨
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.
My code is different from the teacher's one 🤔
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.
I've read the lessons but nothing is clear 🙄
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.
Tips
Definitions
Tests a special code that checks programs for correctness by comparing the result obtained during the execution of the program with the expected result.