# Functions 6. Practice Makes Perfect - INPUT and PRINT results

#1

All that happens is I get a chance to input a number, but I'm not getting shown any of the "print" results.

``````number = input("Enter a number")

def cube(number):
return number ** 3
def by_three(number):
if number % 3 == 0:
return cube(number)
print "number is divisible by 3. the cube is: " + str(cube)
else:
print "%d is not" % (by_three)
return False

by_three(number)``````

#2

Don't use input in python2, it executes the input which is incredibly inappropriate. Instead, read the input with raw_input and convert the result to int.

Note that you have some unreachable code, perhaps that's what you were expecting to print something.

#3

Ok, cool.. thanks!
So now I've done it like this:

``````number = raw_input("Enter a number")

def cube(number):
return number ** 3 #this should be returning the cube of whatever was input, but it's not doing jack! what am I doing wrong?

def by_three(number):
if number % 3 == 0: #I don't see the relation, but ok.. so if the number is divisible by 3, the function by_three will then cube it and return us that result? ok. but why doesn't it work? what's my mistake?
return cube(number)
print "number is divisible by 3. congratulations. here is your cube: " + str(cube)
else:
print "% is not divisible by 3 so you get no cubes buddy" % (by_three)
return False``````

My question is, why can't I get the code to print the results in each step?

#4

oh wait, I totally don't understand what "unreachable code" is.. which lines are those in my code?
I basically want to input a number, then each the function "by_three" would churn out the results and print them.
I'm not able to see what I'm missing here

#5

If you exit the function, then the instructions that follow in the function will not be executed, because you're no longer executing the function, you exited it. That makes those instructions unreachable

#8