[英]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.