Exercise:
year_in = int(input("Please input year:"))
month_in = int(input("Please input month:"))
sum_day = 0
month_sumDay = 0
for year in range(1900,year_in):#days from Jan. 1, 1900 to Dec. 31, year_in -1
if (year%4==0 and year%100!=0) or (year%400==0):
sum_day += 366
else:
sum_day +=365
for month in range(1,month_in):##days from Jan. 1, year_in to the last day of month_in-1
if month == 2:
if (year_in%4==0 and year_in%100!=0) or (year_in%400==0):
sum_day +=29
else:
sum_day+=28
elif month == 4 or month == 6 or month ==9 or month == 11:
sum_day += 30
else:
sum_day += 31
sum_day+=1#add month_in first day
week = sum_day%7
if month_in == 2:
if (year_in % 4 == 0 and year_in % 100 != 0) or (year_in % 400 == 0):
month_sumDay = 29
else:
month_sumDay = 28
elif month_in == 4 or month_in == 6 or month_in == 9 or month_in == 11 :
month_sumDay = 30
else:
month_sumDay = 31
print("\t\tYear: ",year_in,", Month:",month_in)
print("Sun.\tMon.\tTue.\tWed.\tThu.\tFri.\tSat.")
for i in range(0,week):
print(end = "\t\t")
for day in range(1,month_sumDay+1):
print(day,end = "\t\t")
if sum_day%7 == 6:
print()
sum_day +=1
[…] banking system I| |____Unit 27 mimic banking system II| |____Unit 28 Perpetual Calendar I| |____Unit 29 Perpetual Calendar II|____Python Level 4| |____Unit 30 First acquaintance list| |____Unit 31 More operations on lists| […]