Commit b6004899 by BellCodeEditor

save project

parent 3f63554a
Showing with 16 additions and 37 deletions
import turtle
import random
num_list=[0,1,4,5,8,9,13,16,20,23,25,29]
goal_num=20
low=0
high=len(num_list)-1
pen = turtle.Turtle()
pen.color('sienna')
# 画布大小
w = turtle.Screen()
w.bgcolor('wheat') # wheat小麦
def tree(n):
if n>=0:
pen.forward(n)
pen.right(30)
tree(n-10)
pen.left(60)
tree(n-10)
pen.right(30)
pen.up()
pen.backward(n)
pen.down()
pen.speed(100)
# 移动到起点
pen.left(90)
pen.up()
pen.backward(150) # 后退
pen.down()
tree(60)
#pen.down()
#pen.forward(100)
#pen.left(30)
#pen.forward(50)
#pen.up()
#pen.backward(50)
#pen.up()
#pen.backward(50)
#pen.down()
turtle.done()
while low<=high:
mid=(low+high)//2
guess_num=num_list[mid]
if guess_num==goal_num:
print(mid)
break
elif guess_num<goal_num:
low=mid+1
elif guess_num>goal_num:
high=mid-1
\ No newline at end of file
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