简体   繁体   English

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

[英]IndentationError: expected an indented block (python codeacademy)

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 您可能想调用 (使用)功能cube()而不是对其进行定义
(in your by_three() function definition), so your corrected code will be: (在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)

On line 3 def cube(num): you have an extra def and : . 在第3行def cube(num):您有一个额外的def: Remove those 删除那些

When defining a function you need def and colon, where as for calling it you don't need one. 定义一个函数时,您需要def和冒号,而在调用它时则不需要一个。 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)

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

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