Have been stuck on this for hours. Don’t know if I misunderstood the instructions or the code.
Go ahead and share the code you have as well as any errors you are getting. That better equips us to guide and nudge you forward.
To share your code, do this:
Click on the </> icon here in the post reply editor. It creates a code block for you with an opening and closing triple back ticks.
Then from the Python lesson, copy your code.
Then paste it in-between those back ticks where it tells you to put your code.
Hi, @hellofromtonya ! I’m suffering with the same lesson. Please, can i send you my code? Do you help me too?
def greater_less_equal_5(answer): if 2 < 3 : return 1 elif 2 > 3 : return -1 else: return 0 print greater_less_equal_5(4) print greater_less_equal_5(5) print greater_less_equal_5(6)
And the feedback is:
It looks like your function output 1 instead of -1 when answer is 3. Make sure you filled in the if and elif statements correctly!
Issues with your code:
- The function is checking if the number passed into the function is > 5 or < 5 (not 3). I’m not sure where you got
3from in your code.
- You want to use the function’s parameter, which you named
answerto do the comparisons. Why? It makes the function reusable. Notice in the print statements that you are passing in different numbers to be compared to 5.
- Also, the comparisons are: > 5 return 1, else if < 5 return 1, else just return 0.
Let’s walk through the first
- That calls (invokes) the function
greater_less_equal_5()and passes the 4 and assigns it to the function’s parameter, you called
answer = 4.
- If answer > 5, then 1 is returned back and printed.
- If answer < 5, then -1 is returned back and printed.
- Otherwise, 0 is returned back and printed.
See if you can convert that into a function.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.