python_factorial_tail recursion

此页面是否是列表页或首页?未找到合适正文内容。

python_factorial_tail recursion

标签:actorentersecondtabfirheadtextfactorialrecursion

目录

  • 一、Create New Project
    • 1.1 the rules of name
  • 二、hugeng007_01_tail recursion
    • 2.1 Conventional Recursive Factorial
  • 三、The Unknown Word

一、Create New Project
1.1 the rules of name

  • hugeng007_xx(number)_name

二、hugeng007_01_tail recursion
2.1 Conventional Recursive Factorial
def factorial(n):
if n==0:
return 1
return factorial(n-1)*n

  • Execution Process:

f(4)=f(3)*4
f(3)=f(2)*3
f(2)=f(1)*2
f(1)=1

  • the result of executionf(4)=1*2*3*4

    2.2 tail recursion

def factorial(n,acc=1):
if n==0:
return acc
return factorial(n-1,n*acc)
三、The Unknown Word

The First Column
The Second Column

tail
[tel]尾部

recursion
递归[ri‘kesion]

factorial
阶乘

acc
accumulation 叠加器

python_factorial_tail recursion

标签:actorentersecondtabfirheadtextfactorialrecursion

原文地址:https://www.cnblogs.com/hugeng007/p/9362833.html

作者: 大白菜装机

为您推荐

返回顶部