#求闰年和平年 year=random.randint(1900,2023) if (year % 4 ==0 and year % 100 !=0) or (year % 400 ==0): print(f'{year}年是百年一遇的闰年,顺顺利利') else: print(f'现在是{year}年,是平年,平平安安!')
#根据平年闰年求每个月的天数 year=random.randint(1000,2023) month=random.randrange(1,13) month_31=[1,3,5,7,8,10,12] month_30=[4,6,9,11] if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): if month in month_31: print(f'{year}年的{month}月有31天,是润年,平平安安!') elif month in month_30: print(f'{year}年的{month}月有30天,是润年,快快乐乐!') else: print(f'{year}年的{month}月有29天,是润年,顺顺利利!') else: if month in month_31: print(f'{year}年的{month}月有31天,是平年,平平安安!') elif month in month_30: print(f'{year}年的{month}月有30天,是平年,快快乐乐!') else: print(f'{year}年的{month}月有28天,是平年,快快乐乐!')
标签:闰年,python,31,30,month,year,print,平年 From: https://www.cnblogs.com/ygyalex/p/17035238.html