这篇文章主要介绍了python数据分析期末大作业,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获,下面让小编带着大家一起了解一下。
描述:
万年历即一种记录日历的书用Python画简单笑脸代码。
本文通过用多个for循环和if判断语句来制作这个简易的公历万年历。
适合python初学者参考使用~
参考代码:
year = int(input("请输入年份:"))
month = int(input("请输入月份:"))
print('----------------------%d年%d月----------------------' % (year, month))
print("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期日\t")
day = 0
for i in range(1900, year):
if (i % 4 == 0 and i % 100 != 0) or i % 400 == 0:
day += 366
else:
day += 365
def days(x, y):
if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0:
a = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
return a[x]
else:
a = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
return a[x]
monthdays = 0
for j in range(0, month):
monthdays += days(j, year)
totaldays = monthdays + day
space = int(totaldays % 7)
for i in range(space):
print('\t\t', end="")
for k in range(1, days(month, year) + 1):
print("%3d\t\t" % k, end="")
if (k + space) % 7 == 0:
print('\n')
结果:
原文地址1:https://blog.csdn.net/weixin_71092993/article/details/138214735
参考资料:python中用turtle画一个圆形 https://blog.csdn.net/SXIAOYAN_/article/details/140061099