Python Code challenges: Control Flow Code Challenges article

Hi. I found a discrepancy in the following challenge article. In the answer, if had a variable that was not included in the exercise. The exercise (by means of comments in the code) asked for variables 20 and 25 to be tested. However, when done so, the result said, “divisible_by_ten(50) should have returned true, but it returned false”. There never was a 50 variable included in the exercise. I have two screenshots here that show the exercise before entering my code, and after entering and running my code. I have also put a link to the article. Just wanted to mention it so that someone can take a look at it. Thank you (:blush:


https://www.codecademy.com/paths/build-chatbots-with-python/tracks/introduction-to-python-and-chatbots/modules/learn-python3-control-flow/articles/python-code-challenges-control-flow

They do this on purpose. There are some tests that run through the backend (correct me if this is the wrong place) that is doesn’t show you. This is to stop you writing code that only works for the test cases you can see.

1 Like

Are you trying to say that it doesn’t tell you every test that you should run? I don’t know if I quite understand what you mean.

Yes, in many lessons, challenges etc. there are a number of background tests (not shown) that run to try to ensure that the code you created meets the requirements given in the instructions.

The fact you’re provided with some basic test statements for these challenges is probably intended to show how your function should operate rather than to function as actual testing. As per @codeneutrino’s comment it is possible to write code that can pass those two tests but doesn’t actually meet the requirements. For a very very basic idea something like if num == 25: return True could be used to provide the correct output for one of your print statements but it would not meet the actual requirements.

1 Like

Ok. Thanks. I still don’t know what was wrong though, why it didn’t say I got it right.

Have a look at the outputs for the values you did check (20 and 25). Are they actually giving you the correct response, 20 is directly divisible, 25 is not.

Note that in Python every integer except 0 evaluates to True when used as a boolean. You can test things like this with the in-built bool() function though it’s worth just knowing that integer 0 is False.