課程
/后端開發
/Python
/初識Python
def fact(n):
? ? if n==1:
return 1
return n*fact(n-1)?
?
fact(5)
2017-12-14
源自:初識Python 7-5
正在回答
注意行縮進,針對條件的return都要在下一行向右移;你的代碼沒毛病,只是行縮進引起的報錯
我是在fact(5)前加了print 出來的
????if n==1:
????????return n
return n*fact(n-1)
????????return 1
? ? else:
????????return n*fact(n-1)?
少了else:
還有注意左對齊
舉報
學python入門視頻教程,讓你快速入門并能編寫簡單的Python程序
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-01-12
注意行縮進,針對條件的return都要在下一行向右移;你的代碼沒毛病,只是行縮進引起的報錯
2018-01-09
我是在fact(5)前加了print 出來的
2017-12-14
def fact(n):
????if n==1:
????????return n
return n*fact(n-1)
fact(5)
2017-12-14
def fact(n):
? ? if n==1:
????????return 1
? ? else:
????????return n*fact(n-1)?
fact(5)
2017-12-14
少了else:
還有注意左對齊