Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson16-diy2
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
660e221c
authored
Nov 05, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
6e9b6e11
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
25 deletions
my.py
my_search.py
my.py
0 → 100644
View file @
660e221c
from
tkinter
import
filedialog
,
Tk
from
my_search.py
View file @
660e221c
import
random
import
turtle
def
tree
(
le
):
alist
=
[]
if
le
>
0
:
for
i
in
range
(
1
,
101
):
t
.
forward
(
le
)
alist
.
append
(
i
)
t
.
right
(
30
)
num
=
random
.
choice
(
alist
)
tree
(
le
-
10
)
# 请完善二分查找函数binary_search(),查找出num在列表alist里面的索引位置
t
.
left
(
60
)
tree
(
le
-
10
)
def
binary_search
(
alist
,
num
):
t
.
right
(
30
)
low
=
0
t
.
up
()
high
=
len
(
alist
)
-
1
t
.
backward
(
le
)
while
low
<=
high
:
t
.
down
()
mid
=
(
low
+
high
)
//
2
t
=
turtle
.
Turtle
()
guess
=
alist
[
mid
]
t
.
left
(
90
)
if
guess
==
num
:
tree
(
50
)
return
mid
t
.
hideturtle
()
elif
guess
<
num
:
t
.
done
()
low
=
mid
+
1
\ No newline at end of file
elif
guess
>
num
:
high
=
mid
-
1
return
None
a
=
binary_search
(
alist
,
num
)
print
(
"随机数是"
,
num
)
print
(
"它的索引位置是"
,
a
)
\ 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