借鑒,查閱網(wǎng)絡(luò)奏黑,各處學(xué)習(xí)基礎(chǔ)炊邦,實(shí)戰(zhàn)
唯有實(shí)戰(zhàn),才可以進(jìn)步
注意:格式熟史,位置馁害,縮進(jìn),在哪放什么蹂匹,縮進(jìn)多少很重要碘菜,說多了都是眼淚
#!/usr/bin/env python
#coding=utf-8 #這一行一定要在前邊寫,不允許隔一行在第三行寫限寞,不然就會(huì)被忽視
#避免不識(shí)別忍啸,最好在第二行寫,記住位置很重要履植,很重要计雌,很重要
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", #不要加“ ”静尼,它相當(dāng)于 “ \n ”
num += 1
if num % 7 == 0 :
if __name__ == '__main__' : #一定要加這一行白粉,這是在直接運(yùn)行時(shí),運(yùn)行:內(nèi)的
#內(nèi)容鼠渺,否則,在別處調(diào)用時(shí)眷细,會(huì)默認(rèn)執(zhí)行里邊的執(zhí)行步
#步驟拦盹,為避免混亂,所以定要加上
year = input('shu ru nian fen :') #input()處理成數(shù)值行溪椎,raw_input()處理成
#字符串
month = input('shu ru yue fen :')
data_month(year,month)