Practice Makes Perfect


First, def a function called cube that takes an argument called number. Don't forget the parentheses and the colon!
02. Make that function return the cube of that number (i.e. that number multiplied by itself and multiplied by itself once again).
03. Define a second function called by_three that takes an argument called number.
04. if that number is divisible by 3, by_three should call cube(number) and return its result. Otherwise, by_three should return False.

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

What is wrong with that?
Thanks in advance


You need to indent the return part of the if and have the two defs on the the same level of indentation. That's why using the correct formatting in forum really matters when talking about python.


return number***3


As @haxor789 said formatting the code is really important with python. The way you posted your code, you define "by_three" inside of the other function and the if statement has no action to execute if condition is true because the return statement is outside of the if statement and it is calling and returning the cube function by default. You need to remove the space(s) before the def statement for "by_three" and adjust the indentation on the code accordingly. Afterwards, you need to tab the "return cube" statement so that it is under the if statement. Hope this helps :slight_smile:.


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