2017-04-12 64 views
0

我正在我的课程在codeacademy,直到出了问题,无法继续,一点点的帮助,请:(这里是我的代码IndentationError:预计缩进块(蟒蛇codeacademy)

def by_three(num):   
    if num%3 == 0: 
     def cube(num):   
    else:   
     print "False" 

def cube(num): 
    return num**3 

by_three(9) 

我得到。 ..

File "<stdin>", line 4 
else: 
^ 
IndentationError: expected an indented block 
Unknown error. 

我会非常感谢你的帮助的人!

+0

你应该退格其他的然后只需按一次标签。我觉得这不是堆栈溢出值得...虽然... – thesonyman101

+1

你需要更多的速度来问一个合法的问题。 你有'def cube(num):'这将被用来定义一个函数。不知道为什么在那里,但这是你的语法错误的原因。 – MrJLP

回答

0

在第3行def cube(num):你有一个额外def:。删除这些

定义一个函数时,你需要def和冒号,至于调用它,你不需要一个。正确的代码

def by_three(num):  
    if num%3 == 0: 
     cube(num) 
    else:  
     print "False" 

def cube(num): 
    return num**3 

by_three(9) 
1

你可能想呼叫(使用)的功能cube()而不是定义它
(在你的by_three()函数定义),所以你的更正后的代码将是:

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) 
相关问题