I Got 99 Problems, But a Switch Ain't One


#1

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

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

Output is below
-1
None
0
None
1
None

So why this None is also getting printed if I am using print instead of return


#2

You’re printing the result of calling the function, but the function has no result (None)

Most of the time a function shouldn’t be printing anything, it’s usually not part of what it promises to do. For example, it would be strange for a function which doubles numbers to also print the result out. Its job is just to double the number. Not to print it.


#3

Thank you so much I get it :slight_smile:


#4

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