Why does my code return 1 instead of false?


#1

def cube(number):
return number ** 3
def by_three(number):
return number % 3
if number % 3 == 0:
return cube(number)
else:
return False


#2

Which number do you put in to get the return value of 1? You list 2 functions that each return a different value, which one returns what and what do you aim to do? Which exercise is it?

These things will make it easier to us to help you :slight_smile:


#3

I have not put in any number... it is the 'practise makes perfect' quiz n wen I run that code it returns 1..


#4

In order to make the code clearer, I think you should remove:

return number % 3

It doesn't seem to serve any purpose. Apart from that I'm not able to find any mistakes in the code. It could be that the return value 1 is because it takes the first return from the function and skips the rest.


#5

Thanks... i've gotten a soln...


#6

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