Commit 15dc5a3b by BellCodeEditor

auto save

parent e8ac9a19
# 和你的小伙伴用列表讲讲桃园结义的故事,并说说这其中运用了哪些列表知识:
# 来,我给你起个头~
# 从前啊,有三个bro,分别是:刘备、关羽、张飞...
bro1="关羽"
bro2="刘备"
bro3="张飞"
bros=["刘备","关羽","张飞"]
bro1=["关羽",160,8.5]
bro2=["刘备",161,9.1]
bro3=["张飞",166,8.3]
bros[0]="关羽"
bros[1]="刘备"
print(bros)
\ No newline at end of file
import turtle
screen = turtle.Screen()
screen.setup(700, 700)
circle = turtle.Turtle()
circle.shape('circle')
circle.color('red')
circle.speed('fastest')
circle.up()
square = turtle.Turtle()
square.shape('square')
square.color('green')
square.speed('fastest')
square.up()
circle.goto(0, 280)
circle.stamp()
k = 0
for i in range(1, 13):
y = 30 * i
for j in range(i - k):
x = 30 * j
square.goto(x, -y + 280)
square.stamp()
square.goto(-x, -y + 280)
square.stamp()
if i % 4 == 0:
x = 30 * (j + 1)
circle.color('red')
circle.goto(-x, -y + 280)
circle.stamp()
circle.goto(x, -y + 280)
circle.stamp()
k += 3
if i % 4 == 3:
x = 30 * (j + 1)
circle.color('yellow')
circle.goto(-x, -y + 280)
circle.stamp()
circle.goto(x, -y + 280)
circle.stamp()
square.color('brown')
for i in range(13, 17):
y = 30 * i
for j in range(2):
x = 30 * j
square.goto(x, -y + 280)
square.stamp()
square.goto(-x, -y + 280)
square.stamp()
turtle.done()
height = 5
stars = 1
for i in range(height):
print((' ' * (height - i)) + ('*' * stars))
stars += 2
print((' ' * height) + '|')
\ No newline at end of file
from turtle import *
import random
import time
n = 80.0
speed("fastest")
screensize(bg='seashell')
left(90)
forward(3*n)
color("orange", "yellow")
begin_fill()
left(126)
for i in range(5):
forward(n/5)
right(144)
forward(n/5)
left(72)
end_fill()
right(126)
color("dark green")
backward(n*4.8)
def tree(d, s):
if d <= 0: return
forward(s)
tree(d-1, s*.8)
right(120)
tree(d-3, s*.5)
right(120)
tree(d-3, s*.5)
right(120)
backward(s)
tree(15, n)
backward(n/2)
for i in range(200):
a = 200 - 400 * random.random()
b = 10 - 20 * random.random()
up()
forward(b)
left(90)
forward(a)
down()
if random.randint(0, 1) == 0:
color('tomato')
else:
color('wheat')
circle(2)
up()
backward(a)
right(90)
backward(b)
time.sleep(60)
write("圣诞节快乐!!!", move=True, align="left", font=("宋体", 30, "normal"))
done()
\ No newline at end of file
# list = [6,2,4,8,10,1,9,3,7,0,5]
# newlist = []
# newlist.append(list[0])
# for i in range(1,len(list)):
# for j in range(len(newlist)):
# if newlist[len(newlist)-1] < list[i]:
# newlist.append(list[i])
# break
# else:
# if newlist[j] > list[i]:
# newlist.insert(j,list[i])
# break
# print(newlist)
################################################希尔排序###############################################
# data = [16,25,39,27,12,8,45,63]
# def shell(list):
# k = 1 #设置排序的次数
# n = len(list) #获取列表长度
# gap = n // 2 #设置增量分别为4、2、1
# while gap > 0: #当gap增量大于0即可进入循环
# for i in range(gap,n): #从增量开始遍历列表 进行插入排序
# temp = list[i] #temp开始存放第一个数字,表示有序的第一个内容
# j = i - gap #通过i减去增量不断获取索引值
# while j >= 0 and list[j] > temp:
# list[j+gap] = list[j]
# j = j - gap #滚动调整索引变量j
# list[j+gap] = temp
# gap = gap // 2
# print(k)
# print(list)
# k+=1
# shell(data)
################################################希尔排序while循环#####################################################
def shell_sort_while(list):
num = len(list)
gap = num // 2
while gap > 0:
# j = gap
for j in range(gap,num):
i = j
while i > 0:
if list[i] < list[i - gap]:
list[i-gap],list[i] = list[i],list[i-gap]
i -= 1
else:
break
gap // 2
return list
list1 = [3,4,8,9,1,2]
# result = shell_sort_while(list1)
# print(shell_sort_while(list1))
shell_sort_while(list1)
print(list1)
import turtle
screen = turtle.Screen()
screen.bgcolor("black")
pen = turtle.Pen()
pen.speed(0)
colors = ["red","orange","yellow","green"]
for i in range(1,300):
pen.forward(i)
pen.pencolor(colors[i % 4])
pen.right(91)
pen.hideturtle()
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