Commit e03ccce0 by BellCodeEditor

auto save

parent 578e41ee
Showing with 76 additions and 9 deletions
#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
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
total = []
while True:
unit= input("请输入:")
if unit== 'q':
break
else:
total.append(unit)
print(total)
\ No newline at end of file
def price():
total = []
while True:
unit= input("请输入:")
if unit== 'q':
break
else:
try:
unit = int(unit)
except:
print("输入的内容不是一个整数,请输入一个整数")
else:
total.append(unit)
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
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