Fetch the repository succeeded.
#!/usr/bin/python3
"""
万年历
"""
import datetime
import sys
def is_leap(year):
"""判断闰年"""
return (year % 4 == 0 and year % 100 != 0) or year % 400 == 0
def get_days(year, month):
"""获得指定月份的天数"""
days_of_month = [
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
]
days = days_of_month[month]
return days + 1 if is_leap(year) and month == 2 else days
def main():
"""主函数"""
if len(sys.argv) == 3:
month = int(sys.argv[1])
year = int(sys.argv[2])
else:
curr_date = datetime.datetime.now()
year = curr_date.year
month = curr_date.month
m = month + 12 if month < 3 else month
y = year - 1 if month < 3 else year
c, y = y // 100, y % 100
w = y + y // 4 + c // 4 - 2 * c + 26 * (m + 1) // 10
w %= 7
month_names = [
'', 'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
]
print(f'{month_names[month]} {year}'.center(20))
print('Su Mo Tu We Th Fr Sa')
print(' ' * 3 * w, end='')
days = get_days(year, month)
for day in range(1, days + 1):
print(f'{day}'.rjust(2), end=' ')
w += 1
if w == 7:
print()
w = 0
print()
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。