Help?


#1


functions - 6.practice makes perfect


SyntaxError: invalid syntax

I don't understand how to do this can someone help please?


input number 'what number?'

def 'cube' (number):
    return number*number*number

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


#2

by_three should not be in quotes. Take the quotes off and you should be good.


#3

Thanks!!!!! :slight_smile: I will try that now.


#4

i tried removing the quotations, but now my if else statement won't work

number = 27
def cube (number):
return number*number*number

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

it said
Oops, try again. by_three(3) returned instead of 27
does anyone know how to fix this?


#6

First,

Remove the quotes around cube and by_three,

def 'cube' (number):

def 'by_three'(number):

should be,

def cube(number):

def by_three(number):

Next, your if and else statement are not indented properly,

if number % 3 == 0:
    return cube
    else:
        return False

should be,

#For proper control flow
if number % 3 == 0:
    return cube
else:
    return False

#7

number = 27
def cube(number):
return(number*number*number)

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

I have done all of the indententions you said but it still won't work. it says:
File "python", line 7
return cube
^
IndentationError: expected an indented block
can someone help please?


#8

I get it now. thanks :slight_smile:


#9

Remove thsi global variable,

Also, you can shorten this line,

by using the power method,

number**3

Your syntax is correct apart from two things indentation and you should return the cube of number and not just the function cube,

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

changes made,

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