6. Functions Practice makes perfect


#1




I wonder why the program does not print? I know if I add:
print cube(12) then it does, but why if I add it in loop it does not?


I did not stuck, just wonder why the loop does not print?


Replace this line with your code. 
def cube(number):
    return number**3
def by_three(number):
    if number % 3 == 0:
        
        return cube(number)
        print "number is divisible by 3"
        
    else:
        return False
        print "number is not divisible by 3"
cube(12)


#2

Anything after return is unreachable. The interpreter never sees the print statements.

The cube function is a dependency of the by_three function, which is the one we are calling.

 by_three(12)

#3

Thank you, I read about functions, unless function is called it will not execute.


#4

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