Return functions


#1

Hi guys!
I am new with python, I am practicing on the interface. I face a problem in Function section with an exercise of “return”. Here is the exercise and my written code. Please let me know what is wrong with it!

First, def a function called cube that takes an argument called number. Don’t forget the parentheses and the colon!

Make that function return the cube of that number (i.e. that number multiplied by itself and multiplied by itself once again).

Define a second function called by_three that takes an argument called number.

if that number is divisible by 3, by_three should call cube(number) and return its result. Otherwise, by_three should return False

My code:

def cube (number):
  cube=number*number*number
  return cube
def by_three (number):
  if number/3 == 0:
    print "%d cube is %d" % (number, cube)
    return cube
  else:
    return "False"

#2

you return cube (which is a function), you don’t return the cube of that number

you can call another function from within a function.


#4

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