Practice makes perfect lesson


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

I get by_three(1) returned 'False' instead of False


#2

You are expected to return the boolean values True / False but instead you are returning a string
And any line of code that comes after returning a value in the function will be UNREACHABLE(will not be executed)


#3

The first branch of the if statement should be returning the cube of the number, not a Boolean.

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

#4

A post was split to a new topic: New to programming