99 Problems


Hey I know how to get the correct answer from reading the instructions but my questions is to why we get -1, 0, and 1? is the answer undefined? shouldn't we only return one result?



greater_less_equal_5(answer) returns 1 if the argument is bigger than 5, -1 if the argument is smaller than 5 and 0 if the argument is equal to 5. So for different arguments the method returns different values. -1, 0 and 1 are just the values the author chose, they could just as well have chosen 1, 2 and 3.

The method is then called with different arguments:

print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)

The print statement puts out the value returned by greater_less_equal() in the console.

4 is smaller than 5 so the method returns -1 to the print statement.
In the next line the function is called with the argument 5. Thus the method returns 0 to the print statement.
In the last line the method is called with 6 as the argument. Since 6 is bigger than 5, 1 is returned to the print statement.

It's important to note that the method only returns one number each time it's called, but it can be a different number depending on the argument.


Ok, that makes sense, thanks for explaining it to me. I hadn't connected that the print prompts at the bottom of the code were what the bulk of the code was responding to.