python数据分析期末考试题及答案

这篇文章主要介绍了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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值