What does these return commands do? (python)


#1

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

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


#2

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


#3

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!


#4

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


#5

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