python日历模块_python中怎样通过日历模块显示今天是星期几

2018-04-08 回答

#!/usr/bin/evn python

def simplecalendar():

daysofmonth=daysofmonths=daysofyears=month=year=0

yearfun=lambda year:year % 400 ==0 or year % 4==0 and year % 100 !=0

print "*"*30,"calendar","*"*30

year=input("enter year: ")

leap=yearfun(year)

month=input('enter month: ')

assert month in range(1,13),"month must in 1-12"

if month==2:

daysofmonth=29 if leap else 28

else:

daysofmonth=30 if month in [4,6,9,11] else 31

for i in range(1,month):

if i==2:

daysofmonths+=29 if leap else 28

else:

daysofmonths+=30 if i in [4,6,9,11] else 31

for i in range(1900,year):

daysofyears+=366 if yearfun(i) else 365

daysofyears+=daysofmonths

weak=1+daysofyears%7

print "sun\tmon\ttue\twed\tthu\tfri\tsat"

print "\t"*weak,

for i in range(1,daysofmonth+1):

weak+=1

if weak%7!=0:

print i,'\t',

else:

print i,'\n',

if __name__=='__main__':

simplecalendar()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值