Commit 0982fdc1 by BellCodeEditor

save project

parent 37ecb5f1
Showing with 39 additions and 24 deletions
import random import turtle
import random
alist = []
for i in range(1, 101): pen = turtle.Turtle()
alist.append(i) pen.color('sienna')
num = random.choice(alist) pen.speed(0)
# 请完善二分查找函数binary_search(),查找出num在列表alist里面的索引位置
w = turtle.Screen()
def binary_search(alist,num): w.bgcolor('wheat')
less_num = num
high = len(alist)-1 pen.left(90)
low = alist[0] pen.up()
while low <= high: pen.backward(100)
mid = (low+high) // 2 pen.down()
guess = alist[mid]
if guess == less_num: def tree(n):
return mid if n>=0:
elif guess < less_num: if n<=12:
low = mid+1 color_list = ['snow','lightcoral']
else: color = random.choice(color_list)
high = mid-1 pen.color(color)
binary_search(alist,num) pen.pensize(n/3)
print('给的数是',num) else:
\ No newline at end of file pen.color('sienna')
pen.pensize(n/10)
pen.forward(n)
angle = random.random()
pen.right(30*angle)
length = 1.5*random.random()
tree(n-10*length)
pen.left(60*angle)
tree(n-10*length)
pen.right(30*angle)
pen.up()
pen.backward(n)
pen.down()
tree(60)
turtle.done()
\ 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