Need help in Practice Makes Perfect


#1

What is wrong with my code?

def cube(n):
cube = number**3
return cube

def by_three(n):
if n % 3 == 0:
return cube(n)
else:
return false

it says:

File "python", line 7
return cube(n)
^
IndentationError: expected an indented block


#2

It's not a good practice to name variables the same as the function name. This can be written in a single return statement:

def cube(n):
    return n ** 3

In Python, True and False are capitalized

    return False

#3

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

Still shows me error.

 File "python", line 6
    return cube(n)
         ^
IndentationError: expected an indented block

#4

I've formatted your code sample so we can see the indentation. Now the error is readily visible. Add 4 spaces to the indent on that line and you'll be good to go.


#5

A post was split to a new topic: What's the mistake here?