Practice makes perfect


#1

https://www.codecademy.com/courses/python-beginner-c7VZg/1/5?curriculum_id=4f89dab3d788890003000096

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

hi guys.. could you help me figure out what did i do wrong here?
thanks in edvance


def cube(n):
return n * (n*n)
def by_three(n):
    if n % 3 == 0:
        print "number is divisble by 3"
    return cube(n)
    else:
        return False
        print by_three(3)
        print "number is not divisble by 3"


#2

First and for most, it is important to realize that the moment a return keyword is reached, something is returned, and the function ends!

right, now first this bit:

def cube(n):
return n * (n*n)

i would indent the return line, so it is inside the function.
then your by_three function:

def by_three(n):
    if n % 3 == 0:
        print "number is divisble by 3"
    return cube(n)
    else:
        return False
        print by_three(3)
        print "number is not divisble by 3"

lets see, return cube(n) should re-indented so it is inside your if statement.

i would put print "number is not divisble by 3" before return False, since functions end when return is reached.

I would put the function call (print by_three(3)) outside and after the function.

You do understand how python deals with indentation? What indentation is, and how important this is in python since no brackets are used