Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson11_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
e03ccce0
authored
Dec 18, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
578e41ee
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
4 deletions
1.py
2.py
func.py
1.py
0 → 100644
View file @
e03ccce0
#1.导入turtle模块
import
turtle
#创建画笔
pen
=
turtle
.
Pen
()
#设置画笔的绘画速度 格式: 画笔对象.speed(x) x取值范围是0 到 10 0是最快的 从1到10是逐渐增快的
#该代码放的位置要在创建画笔之后,开始画画之前
#pen.speed(0)
#跳过绘画的过程 格式: turtle.tracer(False) / 画笔对象._tracer(False)
# 参数为False表示过程不可见, 参数为True表示过程可见
#如果有填充颜色就不需要使用turtle.update()来进行手动更新
turtle
.
tracer
(
False
)
# #填充颜色第一步:设置要填充的颜色 格式:画笔对象.fillcolor("color"),该代码放的位置要在创建画笔之后,开始画画之前
# turtle.fillcolor("red")
#填充颜色第二步:开始填充 格式:画笔对象.begin_fill(),是一个无参函数,该代码放的位置要在设置填充颜色之后,停止填充之前
#开始填充可以在画画的过程中进行填充,也可以在画画开始之前进行填充
# turtle.begin_fill()
#创建5次循环
for
i
in
range
(
5
):
#画笔移动200步
turtle
.
forward
(
200
)
#画笔右转144度
turtle
.
left
(
144
)
#填充颜色第三步 : 结束填充 格式:画笔对象.end_fill(),是一个无参函数,该代码放的位置要在结束画画的时候
#填充颜色可以是填充一半,也可是填充所有
# turtle.end_fill()
#隐藏画笔形状pen.hideturtle()
turtle
.
hideturtle
()
#需要手动更新格式:turtle.update() / pen._update() 要放在文件最后,但是要放到turtle.done()之前
turtle
.
update
()
#保留画布
turtle
.
done
()
\ No newline at end of file
2.py
0 → 100644
View file @
e03ccce0
import
turtle
pen
=
turtle
.
Pen
()
pen
.
fillcolor
(
"yellow"
)
pen
.
begin_fill
()
for
i
in
range
(
8
):
pen
.
forward
(
50
)
pen
.
left
(
45
)
pen
.
end_fill
()
pen
.
hideturtle
()
turtle
.
done
()
\ No newline at end of file
func.py
View file @
e03ccce0
total
=
[]
while
True
:
def
price
():
total
=
[]
while
True
:
unit
=
input
(
"请输入:"
)
if
unit
==
'q'
:
break
else
:
try
:
unit
=
int
(
unit
)
except
:
print
(
"输入的内容不是一个整数,请输入一个整数"
)
else
:
total
.
append
(
unit
)
print
(
total
)
\ No newline at end of file
return
total
#建立一个求和的函数sum,sum有参函数,参数是price()函数返回的列表
def
sum
(
alist
):
count
=
0
for
i
in
alist
:
count
+=
i
return
count
p
=
price
()
print
(
p
)
s
=
sum
(
p
)
print
(
s
)
\ 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