Commit ecb1edfa by BellCodeEditor

auto save

parent 1bad0edb
Showing with 22 additions and 21 deletions
# 悟空想海龟作图画出弹簧隧道,但是出现了bug,运行不了,请你帮助他,修改bug~
import turtle
import random
alist = []
for i in range(1,101):
alist.append(i)
num = random.choice(alist)
pen=turtle.Pen()
screen=turtle.Screen()
pen.speed()
pen.hideturtle()
screen.bgcolor('black')
i=0
while i<135:
pen.pencolor('pink')
pen.penup()
pen.goto(0,0)
pen.forward(200)
pen.pendown()
pen.circle(100)
pen.left(2)
i+=1
turtle.done()
\ No newline at end of file
#自定义函数 实现二分查找
def search_num(alist,num):
low = 0 #最低索引
high = len(alist)-1 #最高索引
while low<=high:
mid = (low+high)//2 #中间索引
guess = alist[mid] #根据中间索引获取到的值
if guess==num:
return mid;
elif guess<num:
low = mid+1
else:
high = mid-1
return None
result = search_num(alist,num)
print('要查找的数为:',num)
print('索引是:',result)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment