借鉴,查阅网络,各处学习基础,实战
唯有实战,才可以进步
注意:格式,位置,缩进,在哪放什么,缩进多少很重要,说多了都是眼泪
#!/usr/bin/env python
#coding=utf-8 #这一行一定要在前边写,不允许隔一行在第三行写,不然就会被忽视
#避免不识别,最好在第二行写,记住位置很重要,很重要,很重要
def is_leap_year(year):
if year % 4 ==0 and year %100 !=0 or year % 400 == 0 :
return True #True = 1
else :
return False #False = 0
def get_month_days(year,month):
num = month
if num in [1,3,5,7,8,10,12]:
days = 31
elif num in [4,6,9]:
days = 30
elif num == 2 :
if is_leap_year(year):
days = 29
else:
days = 28
else:
print ' you are wrong,try again.'
return days
def get_today(year,month):
sd = sumdays = 0
for i in range(1990,year):
if is_leap_year(year):
sd +=366
else:
sd +=365
for i in range(1,month):
sd += get_month_days(year,i)
return sd
def data_month(year,month):
num = 0
print 'Sun\tWon\tTue\tWed\tThu\tFri\tSat'
for i in range(get_today(year,month) %7+1):
print "\t", #要加,才能一行打印出来
num += 1
for i in range(1,get_month_days(year,month)+1):
print i,
print "\t", #不要加“ ”,它相当于 “ \n ”
num += 1
if num % 7 == 0 :
if __name__ == '__main__' : #一定要加这一行,这是在直接运行时,运行:内的
#内容,否则,在别处调用时,会默认执行里边的执行步
#步骤,为避免混乱,所以定要加上
year = input('shu ru nian fen :') #input()处理成数值行,raw_input()处理成
#字符串
month = input('shu ru yue fen :')
data_month(year,month)
网友评论