Commit 0982fdc1 by BellCodeEditor

save project

parent 37ecb5f1
Showing with 39 additions and 24 deletions
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):
less_num = num
high = len(alist)-1
low = alist[0]
while low <= high:
mid = (low+high) // 2
guess = alist[mid]
if guess == less_num:
return mid
elif guess < less_num:
low = mid+1
else:
high = mid-1
binary_search(alist,num)
print('给的数是',num)
\ No newline at end of file
import turtle
import random
pen = turtle.Turtle()
pen.color('sienna')
pen.speed(0)
w = turtle.Screen()
w.bgcolor('wheat')
pen.left(90)
pen.up()
pen.backward(100)
pen.down()
def tree(n):
if n>=0:
if n<=12:
color_list = ['snow','lightcoral']
color = random.choice(color_list)
pen.color(color)
pen.pensize(n/3)
else:
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