#!/usr/bin/python
# -*- coding: utf-8 -*- def is_leap_year(year): if year % 4 == 0 and year % 400 == 0: return True elif year % 100 == 0 and year % 400 == 0: return True else: return False def get_month_days(year, month): days = 31 if month == 2: if is_leap_year(year): days = 29 else: days = 28 elif month in[4, 6, 9, 11]: days = 30 return days def get_total_days(year, month): total_days = 1 for i in list(range(1900, year)): if is_leap_year(year): total_days += 366 else: total_days += 365 for i in list(range(1, month)): total_days += get_month_days(year, month) return total_days if __name__ == '__main__': while True: print("**************日历**************") year = input("请输入年份(:1990):") month = input("请输入月份:") try: year = int(year) month = int(month) if month < 1 or month > 12: print("输入错误!!!请重新输入") continue break except: print("输入错误!!!请重新输入") continue break if is_leap_year(year): print("%s是闰年"% year) else: print("%s是平年"% year) print("%s月份共有%s天"% (month, get_month_days(year, month))) print("一共多少天%s"% (get_total_days(year, month))) print("日\t一\t二\t三\t四\t五\t六") i_count = 0 #计数器判断是否换行 # a = get_total_days(year, month)/7 # print(a) for i in list(range(1, int(get_total_days(year, month-1)/7)+1)): i_count += 1 a = i_count % 7 print(a) for i in list(range(0, a)): print(" ", "\t", end="") for i in list(range(0, get_month_days(year, month))): # print(i, '\t', end="") i_count += 1 i += 1 if i_count % 7 == 0: print(i) else: print(i, '\t', end="")
python学习(一)
最新推荐文章于 2024-07-21 18:01:44 发布