What does these return commands do? (python)


def greater_less_equal_5(answer):
if answer > 5:
return 1
elif answer < 5:
return -1
return 0

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


When we use the return keyword, it gives the function a value. Now, when we print the function, it prints its value.


the statement return causes the function to to exit and hand back a value to its caller, while print displays what it is programmed to displayed!


Your code is right, I see no problem with it.
Maybe it's the indentation of your code.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.