1 Star 0 Fork 0

wdhxm52/temporary

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
mycal.py 1.33 KB
Copy Edit Raw Blame History
wdhxm52 authored 2019-07-17 15:57 . 添加文件
#!/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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wdhxm52/temporary.git
git@gitee.com:wdhxm52/temporary.git
wdhxm52
temporary
temporary
master

Search