1. 程式人生 > >python3 練習題100例 (四)

python3 練習題100例 (四)

題目四:輸入某年某月某日,判斷這一天是這一年的第幾天?

#!/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}天!')