Again code is marked right, but doesnt execute. :( What am I missing?


Dear Pythoners,
again I ran into the code execution problem - the code is marked as correct, but simply doesn’t show any output on the console side :frowning:
what am I missing?

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

    return False
  print number
  print number ** 3
  print cube(number)


i added format to your code, so the indent shows. Can you tell me that this is what your code looks like? (that the indent is right?)

well, function only execute when called, but you seemed to have placed your function call ( print cube(number)) inside your function body

there is no function call outside any function, so the functions never execute.


that’s what it looks like. I am not sure that understand what you mean…I thought the return is supposed to be part of the body, or is that wrong?


yes, return needs to be inside the body of the function. But this is not what you are having a problem with

for a function to execute, a function needs be called.

Functions are a sort of task list. I can give you a task list (function), now you know the tasks which you need to do, have you actually done these tasks? Nope, i need to tell you to start executing the task list (function call)

now, functions are a bit more complex given function can call other functions

but you need one function call in the main part of your program, otherwise, none of the functions you wrote will execute


Hm. I thought the function call would be number(15). But obviously, that’s not the case from what you said. can you give me a hint?


trying to figure it out myself as well of course :slight_smile:


I think I figured it out…


you have two functions: cube and by_three, so that is what you should be calling

number is the function parameter, as such, you need to supply an argument at function call to satisfy the parameter (the parameter is just a placeholder until it gets its value from the argument at function call)


figured it out after reading through your former answer once again :slight_smile: thanks a lot!


Hi again,
finally I can get back to the task. I was wondering if someone could tell me if my adjustments to the code are correct. The code, fortunately, gets executed now, but I’m wondering if my function call is right…here’s the adjusted code:

def cube(number):
return number ** 3

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

return False

print cube(15)
print by_three (15)

Isn’t the function call supposed to work without the ‘print’ before it? it doesn’t…hm.

Thank’s a lot for your help in advance.


The functions do execute when you call them, even if you do not print the results. However, if you don’t include any print statements at all in your code, the results of calling the functions will not appear on the console.


Ahh! Yeah, that makes sense…okay. Merci!


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