Last answered:

10 Nov 2022

Posted on:

04 Nov 2022

0

Resolved: Why it didn't return "Less" as output?

-3 is also less than 5, so it could return "Less"?

2 answers ( 1 marked as helpful)
Posted on:

04 Nov 2022

3

In the lesson he mentioned that the python program is executed from top to bottom yeah?
So, the second line of the conditional statements elif y < 0 already takes precedence before the elif y < 5 so the initial 'elif' statement executes and the code ends because it has already seen a condition ...

elif y < 0:
    return "Negative

that satisfies the question ( print(compare_to_five(-3)).

I hope this helps.

Instructor
Posted on:

10 Nov 2022

0

Hi Amy and Oluwaseun!
Thanks for reaching out.

@: Oluwaseun
Thanks for sharing this piece of information with the Community!

@: Amy
Oluwaseun said it all. Python executes programs from top to bottom and then the order of the commands matters.

Hope this helps.
Best,
Tsvetelin

Submit an answer