Skip to content

Commit 4d44087

Browse files
committed
move code
move code
1 parent 84ef148 commit 4d44087

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1393
-0
lines changed

chaoxi/cherry_tree/cherry_tree.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import turtle
2+
import random
3+
4+
def cherryTree(branch, t):
5+
if branch > 4:
6+
if 7 <= branch <= 13:
7+
# 随机数生成
8+
if random.randint(0, 3) == 0:
9+
t.color('snow') # 花瓣心的颜色
10+
else:
11+
t.color('pink') #花瓣颜色
12+
# 填充的花瓣大小
13+
t.pensize( branch / 6)
14+
elif branch < 8:
15+
if random.randint(0, 2) == 0:
16+
t.color('snow')
17+
else:
18+
# 设置樱花树叶颜色
19+
t.color('green') # 樱花树颜色
20+
t.pensize(branch / 5)
21+
else:
22+
t.color('Peru') # 树干颜色
23+
t.pensize(branch / 11) #调整树干的粗细
24+
t.forward(branch)
25+
26+
a = 1 * random.random()
27+
t.right(20 * a)
28+
b = 1 * random.random()
29+
cherryTree(branch - 10 * b, t)
30+
t.left(60 * a)
31+
cherryTree(branch - 10 * b, t)
32+
t.right(40 * a)
33+
t.up()
34+
t.backward(branch)
35+
t.down()
36+
37+
# 掉落的花瓣 参数是画板和笔
38+
def petal(m, t):
39+
for i in range(m):
40+
a = 200 - 400 * random.random()
41+
b = 10 - 20 * random.random()
42+
t.up()
43+
t.forward(b)
44+
# 向左移动
45+
t.left(75)
46+
# 向前移动
47+
t.forward(a)
48+
# 放下画笔
49+
t.down()
50+
# 设置花瓣颜色
51+
t.color('pink') # 粉红色
52+
# 画个小圆当作花瓣
53+
t.circle(1)
54+
# 提起画笔
55+
t.up()
56+
# 画笔向后退
57+
t.backward(a)
58+
# 画笔向前行
59+
t.right(70)
60+
t.backward(b)
61+
62+
# 描述樱花的句子
63+
def des_word():
64+
t.color('LightCoral') # 字体颜色设置
65+
t.hideturtle()
66+
t.goto(-50,-130)
67+
t.pu()
68+
# 昨日雪如花,今日花如雪,山樱如美人,红颜易消歇。
69+
t.write('昨日雪如花,',move=False, align='center', font=('Arial', 20, 'normal'))
70+
t.pd()
71+
72+
t.pu()
73+
t.goto(90,-130)
74+
t.write('今日花如雪', move=False, align='center', font=('Arial', 20, 'normal'))
75+
t.pd()
76+
77+
78+
# 绘图区域
79+
t = turtle.Turtle()
80+
# 画布大小 获取到屏幕
81+
w = turtle.Screen()
82+
t.hideturtle() # 隐藏画笔
83+
t.getscreen().tracer(8, 0) # 获取屏幕大小
84+
w.screensize(bg='LightCyan') # 设置屏幕背景颜色
85+
t.left(80)
86+
t.up()
87+
t.backward(140)
88+
t.down()
89+
t.color('sienna')
90+
cherryTree(50, t)
91+
petal(300, t)
92+
des_word()
93+
# 点击屏幕任意地方退出
94+
w.exitonclick()
95+

chaoxi/day-007/__init__.py

Whitespace-only changes.

chaoxi/day-007/sequence.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# 定义一个学生序列
2+
stuinfo = ['zhangsan', 'lisi', 'wangwu', 18, 20]
3+
print(stuinfo)
4+
5+
# 定义学生姓名和学生年龄,然后再定义一个属于自己的数据库将两个列表加入
6+
stuname = ['zhangsan','lisi','wangwu']
7+
stuage = [18, 20, 16]
8+
database = [stuname, stuage]
9+
print('我的学生库信息是:%s ' % database)
10+
print('我的学生库姓名信息是:%s ' % database[0])
11+
print('我的学生库年龄信息是:%s ' % database[1])
12+
13+
# 字符串序列的索引
14+
str = 'hello'
15+
print("下标是0的元素是 :%s" % str[0])
16+
print("下标是1的元素是 :%s" % str[1])
17+
print("下标是-1的元素是 :%s" % str[-1])
18+
print("下标是-2的元素是 :%s" % str[-2])
19+
20+
# 分片
21+
# 构建一个序列tag,里面包含一个元素
22+
tag=['https://www.cnblogs.com/yangyuqig/p/10101663.html']
23+
24+
# 拿到这个元素后通过分片取出一个范围的值
25+
print("下标从0-24的元素内容是:%s " % tag[0][0:24])
26+
27+
num=[1,2,3,4,5,6,7,8,9,10]
28+
29+
# 表示从第四个到最后一个元素
30+
print("数字从3-10的内容是:%s " % num[3:10])
31+
32+
# 分片快捷操作
33+
print("前三个数字是:%s " % num[0:3])
34+
35+
# 按照步长为2返回第1个和第6个之间的元素
36+
print("0-6之间步长为2的元素是:%s " % num[0:6:2])
37+
38+
39+
print("负数分片结果是:%s" % num[7:-1])
40+
41+
print("结果是: %s " %num[-9:-1])
42+
43+
# 提取前6个元素,步长为2
44+
print("前6个元素中步长为2的结果为:%s " % num[:6:2])
45+
46+
# 序列相加
47+
48+
a = 'hello'
49+
b = ' world !'
50+
print("两个序列相加的结果是:%s " % a+b)
51+
52+
# 序列相乘
53+
a = 'hello '
54+
b = a * 3
55+
print("返回序列相乘的结果是:%s " % b)
56+
57+
# 序列的成员资格
58+
str = 'hello'
59+
print('h' in str)
60+
61+
print('x' in str)
62+
63+
# 序列长度、最大值、最小值
64+
print(len([11,34,23]))
65+
66+
print(max(11,34,23))
67+
68+
print(min(11,34,23))

chaoxi/day-008/__init__.py

Whitespace-only changes.

chaoxi/day-008/list.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# 使用list函数
2+
ll = list('hello list')
3+
print(ll)
4+
5+
# 列表元素赋值 如 x[3]=5
6+
x = [1,2,3,4,5]
7+
# 改变列表第四个元素的值
8+
x[3] = 5
9+
print(x)
10+
11+
# 删除元素 del
12+
names = ['zhangsan','lisi','wangwu','zhaoliu']
13+
print(names)
14+
# 删除第三个元素
15+
del names[2]
16+
# 最后列表长度变为3
17+
print(names)
18+
19+
20+
# 分片赋值
21+
name = list('python')
22+
name[2:] = 'wr'
23+
print(name)
24+
25+
# 序列不等长分片替换
26+
name_re = list('perl')
27+
# 替换第一个元素后的所有内容
28+
name_re[1:] = list('ython')
29+
print(name_re)
30+
31+
# 插入新元素
32+
num = [1,4,5]
33+
# 在第一个元素后插入新的元素
34+
num[1:1] = [2,3]
35+
num
36+
print(num)
37+
38+
# 给第一个和迪桑元素之间分片赋值一个空序列,即删除元素
39+
num[1:3] = []
40+
num
41+
[1, 4, 5]
42+
43+
# 负数分片操作
44+
num[-1:-1] = [5,5,5]
45+
print(num)
46+
47+
48+
# 列表方法 追加内容
49+
list_append = [1,2,3,4]
50+
list_append.append(5)
51+
print(list_append)
52+
53+
# 统计列表中某个内容的词频
54+
num.count(5)
55+
56+
57+
# 统计字母a出现的次数
58+
name = ['a','a','abf','ark','nhk']
59+
60+
name.count('a')
61+
62+
63+
# extend 方法
64+
a =[1,2,3]
65+
b = [4,5,6]
66+
# 将列表b追加在列表a后面
67+
a.extend(b)
68+
print(a)
69+
70+
71+
# index 方法
72+
content = ['where','who','lisi','cntent','who']
73+
content.index('who')
74+
75+
# insert 方法
76+
num = [1,2,5,6,7]
77+
num.insert(2,3)
78+
print(num)
79+
num.insert(3,4)
80+
print(num)
81+
82+
83+
# pop 方法
84+
x = [1,2,3]
85+
x.pop()
86+
3
87+
print(x)
88+
x.pop()
89+
print(x)
90+
91+
# remove 方法
92+
content = ['where', 'who', 'lisi', 'cntent', 'who', 'who']
93+
# 移除了第一个匹配的元素
94+
content.remove('who')
95+
print(content)
96+
97+
98+
# reverse 方法
99+
x = [1, 2, 3]
100+
# 元素反向存储
101+
x.reverse()
102+
print(x)
103+
104+
# sort 方法
105+
x = [2,3,5,6,1,4,7]
106+
x.sort()
107+
print(x)
108+
109+
# clear 方法
110+
list1 = ['baidu', 'google', 12, 23]
111+
print(list1)
112+
list1.clear()
113+
print(list1)
114+
115+
# copy 方法
116+
list1 = ['baidu', 'google', 12, 23];
117+
list2 = list1.copy()
118+
print(list2)

chaoxi/day-009/__init__.py

Whitespace-only changes.

chaoxi/day-009/tupple.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
tup1 = ('baidu', 'google', 12, 34);
2+
tup2 = (1, 2, 3, 4, 5 );
3+
tup3 = "a", "b", "c", "d";
4+
tup4 = ()
5+
6+
7+
8+
print(tup1)
9+
10+
print('元组tup3的类型是:%s' % type(tup3))
11+
12+
# 访问元组中元素
13+
tup1 = ('baidu', 'google',1,2)
14+
tup2 = (1, 2, 3, 4, 5, 6, 7)
15+
16+
print("tup1中的第一个元素是:", tup1[0])
17+
print("tup2中的 1-5 范围内的元素是:", tup2[1:5])
18+
19+
# 修改元组
20+
tup1 = ('baidu', 'google',1,2)
21+
tup2 = (1, 2, 3, 4, 5, 6, 7)
22+
tup1 + tup2
23+
24+
# 删除元组
25+
tup1 = ('baidu', 'google', 1, 2)
26+
print(tup1)
27+
# del tup1
28+
# print("删除后的元组 tup1 : ")
29+
# print(tup1)
30+
31+
32+
#元组求长度
33+
tup1 = ('baidu', 'google', 1, 2)
34+
print('元组 tup1 的长度是:%s' % len(tup1))
35+
36+
# 元组连接
37+
tup1 = (1, 2, 3)
38+
tup2 = (4, 5, 6)
39+
tup3 = (7, 8, 9)
40+
join_tup = tup1 + tup2 + tup3
41+
42+
# 复制元组
43+
tup1 = ('复制 abc ')
44+
print(tup1 * 3)
45+
46+
# 指定元素访问
47+
content = ('hello','world','!')
48+
print(content)
49+
print(content[1:])
50+
print(content[:2])
51+
52+
print(content[-1])
53+
54+
print(content[-2])
55+
56+
# 元组内置函数
57+
58+
tup1 = (21, 3, 44, 56, 3, 10)
59+
# 求个数
60+
print('元组 tup1 的长度是:%s' % len(tup1))
61+
62+
# 求最大值
63+
print('元组 tup1 的最大值是:%s' % max(tup1))
64+
65+
# 求最小值
66+
print('元组 tup1 的最小值是:%s' % min(tup1))
67+
68+
# 元组转换
69+
# 元组转为list
70+
list(tup1)
71+
# list转为元组
72+
tuple(tup1)

chaoxi/day-011/__init__.py

Whitespace-only changes.

chaoxi/day-011/dict_fromkeys.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
# dict.fromkeys(seq[, value])
3+
seq = ('name', 'age', 'class')
4+
5+
#
6+
dict = dict.fromkeys(seq)
7+
print("新的字典为 : %s" % str(dict))
8+
9+
dict = dict.fromkeys(seq, 10)
10+
print("新的字典为 : %s" % str(dict))
11+
12+
dict = dict.fromkeys(seq,('zs',8,'Two'))
13+
print("新的字典为 : %s" % str(dict))

chaoxi/day-011/dictionary-in.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
dict = {'Name': 'Mary', 'Age': 20,'Address':'BeiJing'}
2+
3+
# 检测键 Age 是否存在
4+
if 'Age' in dict:
5+
print("键 Age 存在")
6+
else:
7+
print("键 Age 不存在")
8+
9+
# 检测键 Sex 是否存在
10+
if 'Sex' in dict:
11+
print("键 Sex 存在")
12+
else:
13+
print("键 Sex 不存在")
14+
15+
# not in
16+
17+
# 检测键 Name 是否存在
18+
if 'Name' not in dict:
19+
print("键 Name 不存在")
20+
else:
21+
print("键 Name 存在")

0 commit comments

Comments
 (0)