Functions - Practice Makes Perfect with argument


I put arguments at the end of the code. When I ran the script it did not return any number. I was expecting the functions to perform the operations but I only got "None". Can someone explain why I did not get any numbers back? Thank you.

def cube(number):
    return number ** 3

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

        return False



Hi, when you want something to print to the console you use print. So you tell me what's missing here:


Thanks for the quick reply. That was what I was thinking but the example in the lesson made me think otherwise.

In the example, since the argument is in uppercase, I'm expecting the script to display on the console "YOU"RE SHOUTING!". That's why I used "return" and I was expecting the operations to be performed (but it wasn't). So on this example script, nothing will be displayed on the console since "return" was used instead of "print"?

Thanks again.


No, it can still be displayed. You are supposed to have a return statement in the function but notice how you are calling the function:

Right now, you are having 3 and 5 go through both those functions but it's not printing to the console because you never told it to. If you want to print it to the console, you would simply add a print statement in front of those two lines like this:

print cube(3)
print by_three(5)

I'm sure you know this concept, but forgot to use it. :slight_smile: If not, then I'll elaborate per your request.


Thanks! That was bugging me a lot!

If you don't mind, please do elaborate.


Sure thing! When you're doing this:

Then you are telling to the function to do whatever code it has in there. It completes that and moves on, however, we don't know that because it never showed anything to the console. When you tell it to print the function for whatever value, you're just telling it to show you what is the final return statement. Of course if you have other print statements within your function, that will be printed as well. But print is like showing the finished product of the function. Does that make sense?


It does. The function did the operation, it just didn't show me the result because I didn't tell it to. Thanks for the clarification. I now see the distinction. Appreciate it.


Welcome! Glad to help. :slight_smile:


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