Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson5_1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e4fa8f9a
authored
Dec 26, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
4ea37e4a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
5 deletions
1.py
diy1.py
1.py
0 → 100644
View file @
e4fa8f9a
# #功能:将0到99输出
# for i in range(100):#开始值是0 结束值100 步长 1 遵循的规则是取左不取右
# print(i)#输出i
# #功能:
# sum = 0 #初始值为0
# for i in range(1,101):#生成的数字是从1到100
# sum = sum + i #循环主体 赋值语句 将 sum + i 赋值给 sum 功能:求和 将1到100的数字加起来赋值给sum
# print(sum)#没有缩进不包含在循环中
#输出从0到100的偶数
# for i in range(0,101):#从0到100
# if i % 2 == 0: # % 取余 i % 2 == 0 如果一个数是2的倍数,那么这个数就是一个偶数0 2 4 6 8 10
# print(i)
#输出从0到100的奇数
for
i
in
range
(
0
,
101
):
#从0到100
if
i
%
2
!=
0
:
# % 取余 i % 2 != 0 如果一个数不是2的倍数,那么这个数就是一个奇数 1 3 5 7 9 。。。
print
(
i
)
\ No newline at end of file
diy1.py
View file @
e4fa8f9a
...
...
@@ -3,14 +3,19 @@
每次移动都增加画笔移动的长度,并旋转91°,重复执行300次,查看效果
"""
import
turtle
colors
=
(
"red"
,
"orange"
,
"green"
,
"blue"
)
'''
元组和列表类似,同样拥有索引,索引起始值也是0 但是元组一经创建无法改变
'''
pen
=
turtle
.
Pen
()
# 请创造师在下面接着创作
distance
=
1
#变量的初始化放到外边
pen
.
speed
(
0
)
for
i
in
range
(
300
):
pen
.
forward
(
distance
)
distance
+=
1
pen
.
right
(
121
)
pen
.
pencolor
(
colors
[
i
%
4
])
pen
.
fd
(
i
)
pen
.
right
(
91
)
# 隐藏画笔,保存画布
pen
.
hideturtle
()
turtle
.
done
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment