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
935ef2a1
authored
Sep 02, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
adaf6f8a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
0 deletions
ddd.py
ggggg.py
my_search.py
ddd.py
0 → 100644
View file @
935ef2a1
import
random
alist
=
[]
for
i
in
range
(
1
,
101
):
alist
.
append
(
i
)
num
=
random
.
choice
(
alist
)
# 请完善二分查找函数binary_search(),查找出num在列表alist里面的索引位置
def
binary_search
(
alist
,
num
):
mid
=
int
(
input
(
'只让学生玩2h手机/周的方老师是屑'
))
low
=
0
high
=
len
(
num_list
)
while
high
>=
low
:
mid
=
(
low
+
high
)
//
2
if
guess
==
num_list
[
mid
]:
print
(
mid
)
break
elif
guess
>
num_list
[
mid
]:
low
=
mid
+
1
elif
guess
<
num_list
[
mid
]:
high
=
mid
-
1
if
high
<
low
:
print
(
'啊哈哈哈哈焯!'
)
result
=
binary_search
(
alist
,
num
)
print
(
result
)
\ No newline at end of file
ggggg.py
0 → 100644
View file @
935ef2a1
# 使用二分查找法,找出9和20在列表里面的索引
num_list
=
[
1
,
3
,
5
,
8
,
11
,
15
,
17
,
18
,
20
,
21
]
mid
=
int
(
input
(
'只让学生玩2h手机/周的方老师是屑'
))
low
=
0
high
=
len
(
num_list
)
while
high
>=
low
:
mid
=
(
low
+
high
)
//
2
if
guess
==
num_list
[
mid
]:
print
(
mid
)
break
elif
guess
>
num_list
[
mid
]:
low
=
mid
+
1
elif
guess
<
num_list
[
mid
]:
high
=
mid
-
1
if
high
<
low
:
print
(
'啊哈哈哈哈焯!'
)
my_search.py
View file @
935ef2a1
...
...
@@ -7,3 +7,18 @@ num = random.choice(alist)
# 请完善二分查找函数binary_search(),查找出num在列表alist里面的索引位置
def
binary_search
(
alist
,
num
):
low
=
0
high
=
len
(
alist
)
while
high
>=
low
:
mid
=
(
low
+
high
)
//
2
if
num
==
alist
[
mid
]:
return
mid
elif
num
>
alist
[
mid
]:
low
=
mid
+
1
elif
num
<
alist
[
mid
]:
high
=
mid
-
1
if
high
<
low
:
print
(
'啊哈哈哈哈焯!'
)
result
=
binary_search
(
alist
,
num
)
print
(
result
)
\ 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