繁体   English   中英

IndentationError:预期缩进的块(python codeacademy)

[英]IndentationError: expected an indented block (python 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.

非常感谢您的帮助!!

您可能想调用 (使用)功能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)

在第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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM