6. Practice Makes Perfect


#1



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


Your code looks a bit off. Check the console window for errors!


def cube(number):
    return cube
def by_three(number):
    if by_three = cube(number):
        return True
    else:
        return False


#2

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

#3

Using "n" will throw an error as "n" is not defined. Use "number" where "n" is used in this example. Also, in the printed message, it will simply say "n is...". You could use string formatting to input the actual number.

def cube(number):
    return cube
def by_three(number):
    if number % 3 == 0:
        print "%s is divisible by 3" % (number)
    else:
        print "%s is not" % (number)

#4

Not in the instructions. If number is divisible by 3 we are asked to return its cube, otherwise return False (as I recall).


#7

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