I was taking my course at codeacademy until something went wrong and couldn't proceed, a little help please :( here is my code
def by_three(num):
if num%3 == 0:
def cube(num):
else:
print "False"
def cube(num):
return num**3
by_three(9)
I get...
File "<stdin>", line 4
else:
^
IndentationError: expected an indented block
Unknown error.
I will really appreciate your help people!!
You probably wanted to call (use) the function cube()
instead of defining it
(in your by_three()
function definition), so your corrected code will be:
def by_three(num):
if num%3 == 0:
print cube(num) # Instead of your original "def cube(num):"
else:
print "False"
def cube(num):
return num**3
by_three(9)
On line 3 def cube(num):
you have an extra def
and :
. Remove those
When defining a function you need def
and colon, where as for calling it you don't need one. The correct code
def by_three(num):
if num%3 == 0:
cube(num)
else:
print "False"
def cube(num):
return num**3
by_three(9)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.