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
4 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
2db0ac81
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
38 deletions
classes.py
classes.py
View file @
8616a667
'''
'''
#猴子吃桃子
#猴子吃桃
def pench(n):
def p(d):
if n==10:
#出口
if d==10:
return 1
return 1
num = (pench(n+1)+1)*2
n = (p(d+1)+1)*2
return num
return n
peach_num = pench(7)
res = p(6)
print(peach_num)
print(res)
#
请用递归实现1+2+3.
...+num的累加和
#
实现1+2+3+
...+num的累加和
#出口
:
1
#出口
1
def s
um_num(number
):
def s
_n(n
):
if n
umber ==
1:
if n
==
1:
return 1
return 1
sum_temp = sum_num(number-1)
temp = s_n(n-1)
return number+sum_temp
v = n+temp
res = sum_num(3)
return v
res = s_n(3)
print(res)
print(res)
#求阶乘 5! 5!= 5*4*3*2*1
#兔子数量
#兔子数量
def f(n):
def f(n):
if n<=2:
if n<=2:
return 1
return 1
v = f(n-1)+f(n-2)
v = f(n-1)+f(n-2)
return v
return v
# elif n>2:
r = f(20)
# v = f(n-1)+f(n-2)
print(r)
# 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)
'''
'''
#求阶乘
5! 5!
= 5*4*3*2*1
#求阶乘
5!
= 5*4*3*2*1
def
f
(
x
):
def
f
(
x
):
if
x
==
0
:
if
x
==
0
:
return
0
return
0
elif
x
==
1
:
elif
x
==
1
:
return
1
return
1
else
:
else
:
y
=
x
*
f
(
x
-
1
)
y
=
x
*
f
(
x
-
1
)
return
y
return
y
print
(
f
(
5
))
r
=
f
(
5
)
print
(
r
)
This diff is collapsed.
Click to expand it.
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