FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
learn-python3/samples/function/recur.py at master · sofay/learn-python3 · GitHub
sofay
/
learn-python3
Public
forked from
michaelliao/learn-python3
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
learn-python3
/
samples
/
function
/
recur.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
24 lines (20 loc) · 491 Bytes
Breadcrumbs
learn-python3
/
samples
/
function
/
recur.py
Copy path
File metadata and controls
executable file
·
24 lines (20 loc) · 491 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 利用递归函数计算阶乘
# N! = 1 * 2 * 3 * ... * N
def
fact
(
n
):
if
n
==
1
:
return
1
return
n
*
fact
(
n
-
1
)
print
(
'fact(1) ='
,
fact
(
1
))
print
(
'fact(5) ='
,
fact
(
5
))
print
(
'fact(10) ='
,
fact
(
10
))
# 利用递归函数移动汉诺塔:
def
move
(
n
,
a
,
b
,
c
):
if
n
==
1
:
print
(
'move'
,
a
,
'-->'
,
c
)
return
move
(
n
-
1
,
a
,
c
,
b
)
print
(
'move'
,
a
,
'-->'
,
c
)
move
(
n
-
1
,
b
,
a
,
c
)
move
(
4
,
'A'
,
'B'
,
'C'
)
Back
|
FazBrowse Home
|
New Git URL