Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
アッカーマン関数は、次のコードで実装しようとしました
def A(m, n): if m == 0: return n + 1 elif m > 0 and n == 1: A(m - 1, 1) elif m > 0 and n > 0: A(m - 1, A(m, n - 1)) print A(4, 5)
if関数は、ステートメントの 3 つのブランチのうち 2 つに対して何も返しません。m == 0明示的に値を返す場合のみ。
if
m == 0
再帰呼び出しの結果も返す必要があります。
def A(m, n): if m == 0: return n + 1 elif m > 0 and n == 1: return A(m - 1, 1) elif m > 0 and n > 0: return A(m - 1, A(m, n - 1))
明示的な戻り値がない場合、関数はデフォルトの戻り値 で終了しますNone。
None