python3 练习题100例 (四)

2020-01-20 11:56:35 浏览数 (1)

题目四:输入某年某月某日,判断这一天是这一年的第几天?

代码语言:javascript复制
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

""" 题目四:输入某年某月某日,判断这一天是这一年的第几天?"""

__author__ = 'Fan Lijun'

year = eval(input('请输入年份:'))
month = eval(input('请输入月份:'))
day = eval(input('请输入日期:'))
days = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365]
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
    if month > 2:
        today = days[month-1]   day   1
    else:
        today = days[month-1]   day
else:
    today = days[month - 1]   day

print(f'今天是{year}年的第{today}天!')

0 人点赞