import turtle as t
t.screensize(2000, 2000, 'white') # 设置画布大小
t.speed(14)# 设置画笔速度
t.title("National_Flag")
# 绘制旗面
t.pencolor('red')
# t.pu()
t.goto(-300, -200)
t.pd()
t.fillcolor('red')
t.begin_fill()
for i in range(0, 2):
t.fd(600)
t.lt(90)
t.fd(400)
t.lt(90)
t.end_fill()
# 绘制大五角星
t.pu()
t.pencolor('yellow')
t.goto(-260, 120)
t.pd()
t.fillcolor('yellow')
t.begin_fill()
for i in range(0, 5):
t.fd(113.137) # 大星一划的边长
t.rt(144)
t.end_fill()
# 绘制四个小五角星
list1 = [(-100, 160), (-60, 120), (-60, 60), (-100, 20)] # 四个五角星的中心坐标
list2 = [31.98, 8.13, -15.59, -38.66] # 相对角度0的后退1.111需要左转的角度
for j in range(0, 4):
t.seth(0) # 这是海龟头部的角度为0
t.pu()
t.goto(list1[j]) # 定位到五角星中心
t.lt(list2[j]) # 旋转角度,以背向指向大五角星的角尖
t.bk(20) # 从五角星中心到指向大五角星的角尖(龟倒着爬)退一个小圆半径
t.lt(18) # 五角星的半角角度
t.pd()
t.begin_fill()
for i in range(0, 5):
t.fd(113.137 / 3) # 小星一划的边长
t.rt(144)
t.end_fill()
t.up()
t.fd(300)
t.left(-90)
t.fd(80)
t.write("绘制员:\n 20211102011xx\n xxx",True,font=('华文琥珀',13,"normal"))
t.down()
t.pu()
t.ht()
t.done()
#Calendar_Call.py
import calendar
#输入指定的年月
yy=int(input("输入年份:"))
mm=int(input("输入月份:"))
#显示月日历
print(calendar.month(yy,mm))
#显示年日历
print(calendar.prcal(yy,m=6))#使用calend里的prcal函数,m参数可以显示几个月 几个月为一行输出[将12个月分为几列]
#给定某一天,判断是星期几
print(calendar.weekday(2022, 9, 9))
#判断是不是闰年
print(calendar.isleap(2022))
import turtle
turtle.setup(500, 500) # 设置画布尺寸
turtle.pensize(7) # 设置画笔尺寸
turtle.pencolor("yellow") # 设置画笔颜色
turtle.fillcolor("red") # 设置填充颜色
turtle.penup() # 提起画笔
turtle.goto(-120, 50) # 画笔从默认画布中心移动往X轴负方向移动120像素点,往y轴正方向移动50像素点
turtle.pendown() # 放下画笔
turtle.begin_fill() # 画笔开始填充
for i in range(5): # 设置循环次数为5,两条边为一次循环
turtle.fd(100) # 画笔向前画100像素单位
turtle.left(72) # 左拐72度
turtle.fd(100) # 画笔向前画100像素单位
turtle.right(144) # 右拐144度
turtle.end_fill() # 结束填充
turtle.done() # 程序运行完,画布窗体不关闭
#WanNianLi_Month.py
#coding=utf-8
__author__ = 'xxx'
def is_leap_year(year):
#判断是否为闰年
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
return True
else:
return False
def get_num_of_days_in_month(year,month):
#给定年月返回月份的天数
if month in (1,3,5,7,8,10,12):
return 31
elif month in (4,6,9,11):
return 30
elif is_leap_year(year):
return 29
else:
return 28
def get_total_num_of_day(year,month):
#自1800年1月1日以来过了多少天
days = 0
for y in range(1800,year):
if is_leap_year(y):
days += 366
else:
days += 365
for m in range(1,month):
days += get_num_of_days_in_month(year,m)
return days
def get_start_day(year,month):
#返回当月1日是星期几,由1800.01.01是星期三推算
return (3 + get_total_num_of_day(year,month)) % 7
#月份与名称对应的字典
month_dict = {1:'January',2:'February',3:'March',4:'April',5:'May',6:'June',7:'July',8:'August',9:'September',10:'October',11:'November',12:'December'}
def get_month_name(month):
#返回当月的名称
return month_dict[month]
def print_month_title(year,month):
#打印日历的首部
print('',get_month_name(month),' ',year,' ')
print('------------------------------------------------------------')
print(' Sun Mon Tue Wed Thu Fri Sat ')
def print_month_body(year,month):
#打印日历正文,格式说明:空两空格,每天长度为5,需要注意的是print加逗号会多一个空格
i = get_start_day(year,month)
#print(i)
print(' ' * i,end='')#从星期几开始则空5*几个空格
for j in range(i,get_num_of_days_in_month(year,month)+1):
print('%5d' %j,end='')#宽度控制,4+1=5
i += 1
if i % 7 == 0 : #i用于技术和换行
print('')#每换行一次行首继续空格
year = int(input("Please input target year:"))
for month in range(1,13):
print_month_title(year,month)
print_month_body(year,month)
print()
这篇博客展示了如何使用Python的turtle模块绘制中国国旗,并利用calendar模块生成日历。首先,通过turtle库详细地绘制了国旗的各个元素,包括红色背景、大五角星和四个小五角星。然后,介绍了calendar模块的基本用法,如显示指定年月的日历、判断闰年、获取某一天是星期几等。代码清晰,易于理解,适合Python初学者学习。
555

被折叠的 条评论
为什么被折叠?



