Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson14-diy1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8616a667
authored
Apr 11, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
2db0ac81
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
39 deletions
classes.py
classes.py
View file @
8616a667
'''
#猴子吃桃子
def pench(n):
if n==10:
#猴子吃桃
def p(d):
#出口
if d==10:
return 1
num = (pench(n+1)+1)*2
return num
peach_num = pench(7)
print(peach_num)
n = (p(d+1)+1)*2
return n
res = p(6)
print(res)
#
请用递归实现1+2+3.
...+num的累加和
#出口
:
1
def s
um_num(number
):
if n
umber ==
1:
#
实现1+2+3+
...+num的累加和
#出口
1
def s
_n(n
):
if n
==
1:
return 1
sum_temp = sum_num(number-1)
return number+sum_temp
res = sum_num(3)
temp = s_n(n-1)
v = n+temp
return v
res = s_n(3)
print(res)
#求阶乘 5! 5!= 5*4*3*2*1
#兔子数量
def f(n):
if n<=2:
return 1
v = f(n-1)+f(n-2)
return v
# elif n>2:
# v = f(n-1)+f(n-2)
# return v
res = f(6)
print(res)
#汉诺塔
def hlt(n):
if n==1:
return 1
count = 2*hlt(n-1)+1
return count
res = hlt(3)
print(res)
r = f(20)
print(r)
'''
#求阶乘
5! 5!
= 5*4*3*2*1
#求阶乘
5!
= 5*4*3*2*1
def
f
(
x
):
if
x
==
0
:
return
0
elif
x
==
1
:
return
1
else
:
y
=
x
*
f
(
x
-
1
)
y
=
x
*
f
(
x
-
1
)
return
y
print
(
f
(
5
))
r
=
f
(
5
)
print
(
r
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment