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
def375df
authored
Apr 02, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
0f53c1f3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
0 deletions
diy1.py
diy2.py
diy3.py
diy4.py
diy1.py
0 → 100644
View file @
def375df
#一个函数在内部直接或间接调用函数本身,我们把这种情况称为递归。
#递归的过程分为两步:
#将问题一层一层的传递下去,叫做递;
#到达最后一层后(边界),利用最后一层的答案,将问题一步步解决,这个过程叫做归。
#递归做累加 1+2+3+4+……+num
def
sum_number
(
num
):
#递归的边界(出口)
if
num
==
1
:
return
1
else
:
temp
=
num
+
sum_number
(
num
-
1
)
return
temp
result
=
sum_number
(
999
)
print
(
result
)
\ No newline at end of file
diy2.py
0 → 100644
View file @
def375df
#请计算出第几列斐波那契数列会大于20
def
func
(
n
):
if
n
<=
2
:
return
1
else
:
value
=
func
(
n
-
1
)
+
func
(
n
-
2
)
return
value
for
i
in
range
(
0
,
20
):
if
func
(
i
)
>
20
:
print
(
'第'
,
i
,
'列斐波那契数列会大于20'
)
break
\ No newline at end of file
diy3.py
0 → 100644
View file @
def375df
#求阶乘 1*2*3*4****n n * n-1 * n-2 * n-3 * …… * 1
#找出阶乘值大于等于600的数
def
func
(
n
):
if
n
==
1
:
return
1
else
:
value
=
n
*
func
(
n
-
1
)
return
value
for
i
in
range
(
1
,
20
):
if
func
(
i
)
>=
600
:
print
(
i
)
break
diy4.py
0 → 100644
View file @
def375df
def
power
(
x
,
y
):
if
y
==
0
:
return
1
else
:
return
x
*
power
(
x
,
y
-
1
)
print
(
power
(
2
,
3
))
\ No newline at end of file
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