# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: simple_calender
Description :
Author : t_lishu
date: 10/18/2018
-------------------------------------------------
Change Activity:
10/18/2018:
-------------------------------------------------
"""
__author__ = 't_lishu'
# 输出日历界面
import sys
thirty_month_list = [4,6,9,11]
# 定义全局变量用于记录天数总和
def is_leap_year(year):
if (year % 4 == 0 and year % 100 != 0) or \
year % 400 == 0:
return True
else:
return False
def get_total_days():
total_days = 1
if year_int >= 2018:
for year_every in range(2018, year_int):
if is_leap_year(year_every):
total_days += 366
else:
total_days += 365
for month_every in range(1, month_int):
if month_every in thirty_month_list:
total_days += 30
elif month_every == 2:
if is_leap_year(year_int):
total_days += 29
else:
total_days += 28
else:
total_days += 31
else:
print("系统正在维护暂时无法获取2018年之前的信息")
return total_days
def get_month_days():
day = 0
if month_int in thirty_month_list:
day = 30
elif month_int == 2:
if is_leap_year(year_int):
day = 29
else:
day = 28
else:
day = 31
return day
def main(month):
total_days = get_total_days()
# 定义变量用于定义每个月的天数
month_days = get_month_days()
# 定义变量 用于计算当月第一天为周几
weak = total_days % 7
print("-----------{0}月-----------".format(month))
print("日\t一\t二\t三\t四\t五\t六")
# 输出指定空格数让第一天与周几对齐
print("\t"*weak, end="")
i = 1
while i <= month_days: # 遍历用户查询月份
weakend = ((total_days+i)-1)% 7
# 如果余数为6 换行否则输出空格
if weakend == 6:
print("%d" % i)
else:
print(i, end="\t")
i += 1
print("\n")
if __name__ == "__main__":
year_int = int(sys.argv[1])
for month_int in range(1, 13):
main(month_int)