import turtle as t
import random as r
r.seed(1)
t.pensize(2)
t.pencolor('red')
angles = 6
points= [[0,0],[50,40],[70,80],[-40,30]]
for i in range(4):
x0,y0 = points[i]
t.penup()
t.goto(x0,y0)
t.pendown()
length = r.randint(6, 16)
for j in range(angles):
t.fd(length)
t.backward(length)
t.right(360 / angles)
t.done()
首先两个库都要进行引用,使用 r.seed 设定一个种子,t.pencolor 设定雪花的颜色,此时看清题目中要求的是绘制4个雪花,确定range的取值范围。penup是起笔,goto 是起到画笔的位置,pendown是停笔,fd是往前走,backward是回来。
fi = open("PY301-vacations.csv","r")
ls = []
for line in fi:
ls.append(line.strip("\n").split(","))
s = input("请输入节假日名称:")
for line in ls:
if s == line[1]:
print("{}的假期位于{}-{}之间".format(line[1],line[2],line[3]))
fi.close()
fi = open("PY301-vacations.csv","r")
ls = []
for line in fi:
ls.append(line.strip("\n").split(","))
s = input("请输入节假日序号:").split(" ")
while True:
for i in s:
for line in ls:
if i == line[0]:
print("{}({})假期是{}月{}日至{}月{}日之间".format((line[1]),(line[0]),line[2][:-2],line[2][-2:],line[3][:-2],line[3][-2:]))
s = input("请输入节假日序号:").split(" ")
fi.close()
fi = open("PY301-vacations.csv","r")
ls = []
for line in fi:
ls.append(line.strip("\n").split(","))
s = input("请输入节假日序号:").split(" ")
while True:
for i in s:
flag = False
for line in ls:
if i == line[0]:
print("{}({})假期是{}月{}日至{}月{}日之间".format((line[1]),(line[0]),line[2][:-2],line[2][-2:],line[3][:-2],line[3][-2:]))
flag = True
if flag == False:
print("输入节假日编号有误!")
s = input("请输入节假日序号:").split(" ")
fi.close()